这应该是商店中系统的代码,如果有人想买别的东西,它会一次又一次地循环。请帮忙。menu=["apple","water","juice"]apple=50water=80juice=100money=int(input("How much money in pennies do you have?"))if money>=100: print("We have the following items you can buy: apple, water, juice")elif money>=80 and money<=100: print("We have the following items you can buy: apple, water")elif money>=50 and money<=80: print("We have the following item you can buy: apple")else: print("Sorry, you can't buy anything.")buy=input("What do you want to buy?")if buy=="apple": print("You have",money-50)elif buy=="water": print("You have",money-80)else: print("You have",money-100)other=(input("Do you want to buy anything else?"))if other=="yes": while x=0: print(x) continueelif other=="no": x+1else: print("Error")最后一部分不起作用 - 有人可以修复它吗?这是 Python 3-谢谢。
2 回答
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
other=(input("Do you want to buy anything else?"))
if other=="yes":
while x=0: <-- should use x==0, but x is not declared
print(x) <-- wrong indentation
continue
elif other=="no":
x+1 <-- even if x was declared, this only sum and nothing
else: more (nothing changes in your program)
print("Error")
即使它有效,这最后一部分基本上也没有任何用处。我建议您使用其他答案中发布的代码。
添加回答
举报
0/150
提交
取消