我需要一些帮助来启动和停止此购物清单中的循环。我需要能够选择一些项目添加总计和税,然后给用户选择结束。我已经将存款或税款单独列入实际支票。然后你会在最后得到一个总计。如果您发现任何其他错误,请随时告诉我们。谢谢
#Welcome user to user display product and prices
print("Hello, welcome to the store")
print("This is the list & products")
print("0,Milk,$2.39/Gallon")
print("2,Eggs,$1.58/per dozen")
print("4,Water,$1.00/Bottle+$.05 deposit")
print("6,Soda,$.99/Can+$.05 deposit")
print("8,Bread,$2.99/Loaf")
print("10,Chips,$1.30/Bag")
print("12,Tomato,$1.99/Pound")
print("Ready-food box,$8.99/Box+$.0625 tax")
#Prompt users for his product
totalpurchase=0
wdeposit=.05
sdeposit=.05
rtax=.0625
gtotal=0
totwdeposit=0
totsdeposit=0
totrtax=0
while 0:
choice=int(input("Enter your product code"))
if choice==0:
qofmilk=int(input("How many gallons do you wish to purchase?"))
totmilk=qofmilk*2.39
print("Your total price for milk is", totmilk)
totalpurchase=totalpurchase+totmilk
if choice==2:
qofeggs=int(input("How many dozen of eggs do you wish to purchase?"))
toteggs=qofeggs*1.58
print("Your total price for eggs is", toteggs)
totalpurchase=totalpurchase+toteggs
if choice==4:
qofwater=int(input("How many bottles of water do you wish to purchase?"))
totwater=qofwater*1.00
print("Your total price for water is", totwater)
totalpurchase=totalpurchase+totwater
if choice==6:
qofsoda=int(input("How many cans of soda do you wish to purchase?"))
totsoda=qofsoda*.99
print("Your total price for soda is", totsoda)
totalpurchase=totalpurchase+totsoda
if choice==8:
qofbread=int(input("How many loafs of bread do you wish to purchase?"))
totbread=qofbread*2.99
print("Your total price for bread is", totbread)
totalpurchase=totalpurchase+totbread
if choice==10:
qofchips=int(input("How many bags of chips do you wish to purchase?"))
totchips=qofchips*1.30
print("Your total price for chips is", totchips)
totalpurchase=totalpurchase+totchips
if choice==12:
qoftomato=int(input("How many pounds of tomatoes do you wish to purchase?"))
tottomato=qoftomato*1.99
print ("Your total price for tomatoes is", tottomato)
totalpurchase=totalpurchase+tottomato
if choice==14:
qofchicken=int(input("How man pounds of chicken do you wish to purchase?"))
totchicken=qofchicken*2.99
print("Your total price for chicken is", totchicken)
totalpurchase=totalpurchase+totchicken
if choice==16:
qofready=int(input("How many boxes of ready-food boxes do you wish to purchase?"))
totready=qofready*8.99
print("Your total price for ready-food boxes is", qofready)
totalpurchase=totalpurchase+totready
print(totalpurchase)
if choice==4:
wdeposit=wdeposit*1
totwdeposit=wdeposit*qofwater
print("deposit", totwdeposit)
if choice==6:
sdeposit=sdeposit*1
totsdeposit=sdeposit*qofsoda
print("deposit", totsdeposit)
if choice==16:
rtax=rtax*1
totrtax=rtax*qofready
print("tax", totrtax)
gtotal=totalpurchase+totwdeposit+totsdeposit+totrtax
print("Your grand total is", gtotal)
while 1:
action=input("press any key if you like to purchase otherwise type end to finish")
if action=="end":
break
答案 0 :(得分:0)
我会设置一个变量来结束循环,当用户想要停止添加项目时,然后将变量设置为其他内容。
done = false
while done:
if choice == 0:
...
(prompt user to continue)
if user is done:
done = true