mardi 15 novembre 2016

Python is ignoring my if statements inside the loop

I'm trying make a loop to ask the user for a selection which is a string, convert it into an integer, and calculate the total and keep asking until the user inputs q for quit. Everything goes well except that my if statements are completely ignored by Python. Can anyone help me?

My code so far looks like this:

l = 0.89
g = 2.50
p = 0.50
t = 0.75
o = 0.50
Subtotal = 0
Total = 0
q = ""
quanity = 0
choice = ""

choice = input('L - Lettuce \nG - Green Beans \nP - Peppers \nT - Tomatoes \nO - Onions \nS - Seasonal Item \nQ - Quit')

while choice != q:
   Subtotal = 0
   quanity = 0
   quanity = input('How Many?')
   if choice == l:
      choice = 0.89
   elif choice == g:
      choice = 2.50
   elif choice == p:
      choice = 0.50
   elif choice == t:
      choice = 0.75
   elif choice == o:
      choice = 0.50
   Subtotal = choice * quanity
   Total = Total + Subtotal
   print('Your total so far is $' ,Total)
   choice = ""
   choice = input('L - Lettuce \nG - Green Beans \nP - Peppers \nT - Tomatoes \nO - Onions \nS - Seasonal Item \nQ - Quit')
print('All Done')

Aucun commentaire:

Enregistrer un commentaire