Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Gtting input ina loop

I want to get the inputs in a loop and I want to show the user they are entering data for the 1st,2nd,3rd, etc items in that loop, can anyone help me please with fixing my code?

n=int(input("Pleaseenter the number of laptops: "))
i=0
while i!=n:
laptops_price=input("Please enter the price of the {i}laptop: ".format(i))
i+=1

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have confused f strings with format calls. They are not quite the same. Either of these will work:

laptops_price=input(f"Please enter the price of the {i}laptop: ")
laptops_price=input("Please enter the price of the {}laptop: ".format(i))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading