Python餐厅程序



我是python初学者&这是我的第三期节目。我在学习函数。用户应该能够从菜单(1)中选择一个数字。开胃菜,2。电源3。饮料,4。每个菜单都有子选项(例如开胃菜包括沙拉、薯条等)。用户应该能够返回后,选择一个项目。我卡在查看订单选项中,用户需要能够看到他们的订单中的每个项目+每个项目旁边的价格&最后,我希望能够显示总账单。如何查看用户的所有订单?我怎样计算总数?我应该使用循环吗?


def menu():
print("--MCQUAN MENU--")
print("1. Appetizers")
print("2. Mains")
print("3. Drinks")
print("4. Desserts")
print("5. View order")
print("6. Exit")
print()
def user_option():
choice = int(input("Choose from the menu & enter a number 1-6: "))
if choice == 1:
print()
print("APP - heres the apps")
print("Salad - $5")
print("Chips & salsa - $6")
print("Soup - $10")
elif choice == 2:
print("MAINS - here the mains")
print("Pasta - $13")
print("Burger - $12")
print("Pizza - $10")
elif choice == 3:
print("DRINKS - heres drinks")
print("Water - $0")
print("Tea - $3")
print("Sprite - $2")
elif choice == 4:
print("DESSERTS - heres desserts")
print("Cake - $6")
print("Ice cream - $5 ")
print("Pie - $7")
elif choice == 5:
print("VIEW ORDER -- heres ur order so far")
elif choice == 6:
print("Exiting")
else:
print("Invalid")
choice = int(input("Enter number 1-6"))
def app():
cost = 0
total = 0
user_food = input("Choose which u want ")
if user_food == "salad":
cheese = input("Cheese? (+$0.50) yes/no ")
dressing = input("Dressing? (+$1) yes/no ")
elif user_food == "chips & salsa":
spicy = input("Spicy? yes/no ")
cilantro = input("Cilantro? yes/no ")
elif user_food == "soup":
soup = input("Chicken noodle or mushroom? ")
else:
print("Alright!")
user_option()
user_food = input("Choose which u want ")
def main():
user_food = input("Choose which u want ")
if user_food == "pasta":
cheese_2 = input("Cheese? yes/no ")
chilli_f = input("Chilli flakes? yes/no ")
elif user_food == "burger":
onions = input("Onions? yes/no ")
pickles = input("Pickles? yes/no ")
elif user_food == "Pizza":
pizza = input("Cheese or pepperoni? ")
else:
print("Alright!")
user_option()
user_food = input("Choose which u want ")
def drinks():
user_food = input("Choose which u want ")
if user_food == "water":
size = input("Small, medium or large? ")
user_option()
user_food = input("Choose which u want ")
def desserts():
user_food = input("Choose which you want")
if user_food == "cake":
w_c = input("Whipped cream? yes/no ")
cherry = input("Cherry? yes/no ")
elif user_food == "ice cream":
w_c = input("Whipped cream? yes/no")
cherry = input("Cherry? yes/no ")
elif user_food == "pie":
w_c = input("Whipped cream? yes/no")
cherry = input("Cherry? yes/no ")
else:
print("Alright")
user_option()
user_food = input("Choose which u want ")


#main
menu()
print("Welcome to McQuans!")
print()
user_option()
app()
main()
drinks()
desserts()`

理想情况下,您不希望将数据保存在打印中。我们可以使用listsdicts

这样的数据结构我的建议是:

  • 我们为客户端订单使用list,因为我们可以继续添加它,我们将按顺序添加东西。
  • 我们使用dicts(python字典)的菜单,所以我们可以跟踪每个菜单的所有项目和每个项目的价格。
client_order = []
app_menu = {
"Salad": 5,
"Chips & salsa": 6,
"Soup": 10
}

如果你不熟悉它们,请查看这个字典教程。

好的,让我们从这个开始。一旦你掌握了它,如果你需要的话,我会再帮你的。

最新更新