我正在尝试为用户创建一个菜单。用户必须订购至少3件商品,之后需要决定是继续订购还是结束订购。我为此创建了while循环,现在这是我的问题
我在定义中包括了用户答案,否则我的循环就不能像我希望的那样工作。。。我需要总结每个不同价格的选择,这些价格需要匹配我创建的列表中的位置
我尝试了def内部和外部的if语句。比如,若输入的答案是=1,那个么价格将是1,20等等,并试图把它加起来,就行不通了。 非常感谢您的帮助
prices = [1.20,1.30,2.00,1.60,2.00,2.50,4.00,4.80,3.80,3.25,3.40,2.70,2.50,3.15,4.40]
food_menu = ["sandwich","pizza","lemon cake","chips","salad","panini","yoghurt","pasta","bagel,"cheese wrap","cherry muffin","egg","blt","marmite sarnine","watermelon pieces"]
def order1():
input("Please choose which treat you wish to order by typing its position number [1-15] and confirm with ENTER : ")
input("Next item to order: ")
def order2():
input("Another item number to order: ")
if decision == "y":
print ("Awesome! Let's get started!")
order1()
i=1
x=""
while i>0:
if decision == "y":
order2()
x = input("Keep adding more food for bigger discount?\ny - for yes\ns - for stop:\nYour answer: ")
if (x == "s"):
break
elif decision == "n":
print ("Please come back tomorrow or try again. Today you need to get minimum 3 items today!\U0001F641")
print ("Bye bye!")
i=0
exit()
else:
print ("Wrong answer, please try again from the start.. \U0001F641 ")
i=0
exit()
之后,我应该总结客户想要订购的每种商品的所有价格
我建议你有一个主回路,然后有两个部件
另外
dict
是存储菜单和价格的最佳结构,它提供了简单的访问和非常好的测试包含相关问题 更多 >
编程相关推荐