使用 Python 循环的 H3lp 高中生

这应该是商店中系统的代码,如果有人想买别的东西,它会一次又一次地循环。请帮忙。


menu=["apple","water","juice"]

apple=50

water=80

juice=100



money=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)

    continue

elif other=="no":

  x+1

else:

  print("Error")

最后一部分不起作用 - 有人可以修复它吗?这是 Python 3-谢谢。


慕仙森
浏览 153回答 2
2回答

天涯尽头无女友

other=(input("Do you want to buy anything else?"))if other=="yes":&nbsp; &nbsp;while x=0:&nbsp; &nbsp; &nbsp; &nbsp; <-- should use x==0, but x is not declared&nbsp; &nbsp;print(x)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <-- wrong indentation&nbsp; &nbsp; &nbsp; &nbsp;continueelif other=="no":&nbsp; &nbsp; x+1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <-- even if x was declared, this only sum and nothing&nbsp;else:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; more (nothing changes in your program)&nbsp; &nbsp; print("Error")即使它有效,这最后一部分基本上也没有任何用处。我建议您使用其他答案中发布的代码。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python