mercredi 14 octobre 2020

while True and if statement printing the same calculation

I am working on a feet to inches converter that is actually very easy to create, as I have done it before. But this time, I am required to use a while loop. Basically, if the number of feet is equal to 0, it shoud print 'the program has finished successfully.' If the number of feet is greater than or equal to 1, the code will continue to make calculation until user input of 0 quits the script. My issue is that when I test quit the script, it prints: "0 feet = 0 inches the program has finished successfully." I just want it to print the termination message, not 0 feet = 0 inches. I can't figure out what I am doing wrong.

def feet_to_inches(feet):
return 12 * feet

feet = int(input('Enter the number of feet (or 0 to end): '))
inches = feet_to_inches(feet)
print(f'{feet} feet = {inches} inches')

while True:
    if feet == 0:
        print('The program has finished successfully.')
        break
    ...       
    if feet >= 1:
        feet = int(input('Enter the number of feet (or 0 to end): '))
        inches = feet_to_inches(feet)
        print(f'{feet} feet = {inches} inches')
        continue

Aucun commentaire:

Enregistrer un commentaire