You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Python/点餐系统 王欣怡.py

115 lines
4.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

menus = [
{"m_name": "鱼香肉丝", "m_money": 33, "m_goods": 0, "m_number": 10},
{"m_name": "麻婆豆腐", "m_money": 11, "m_goods": 0, "m_number": 10},
{"m_name": "水煮肉片", "m_money": 66, "m_goods": 0, "m_number": 10},
]
menus_car =[]
orders =[]
# 2.点击我要点菜,显示所有菜品信息及编号。
while True:
print("----------点餐系统----------")
print("1.我要点餐")
print("2.我要结账")
print("3.我要点赞")
print("4.退出系统")
print("请选择编号:",end="")
num1 = int(input())
if num1 ==1:
while True:
menu_no = 1
print(" ")
print("----------点餐界面----------")
print("菜单编号\t\t菜单名称\t\t单价\t\t点赞数\t\t剩余库存")
for menu in menus:
print("{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}\t\t".format(
menu_no,
menu.get("m_name"),
menu.get("m_money"),
menu.get("m_goods"),
menu.get("m_number")
))
menu_no += 1
# 3.用户选择编号,将菜品添加到购物车,并扣除菜品信息中的分数。
print("请选择菜品编号(0返回首页) ",end="")
user_menu_no = int(input()) #用户输入菜品编号
if user_menu_no==0:
break
print("请输入购买份数:", end="")
user_menu_number = int(input())
# 计算菜品总价
user_menu_money = menus[user_menu_no-1].get("m_money") * user_menu_number
#1.获得菜品信息
new_menus = menus[user_menu_no - 1] #将点菜信息赋值给新的变量
new_menus.update({"user_menu_number":user_menu_number})
new_menus.update({"user_menu_money":user_menu_money})
#2.放入购物车
menus_car.append(new_menus)
elif num1 ==2:
print(" ")
print("----------结账界面----------")
print("菜单名称\t\t单价\t\t份数\t\t总价")
goodsum = 0;
for menucar in menus_car:
goodsum += menucar.get("user_menu_money")
print("{0}\t\t{1}\t\t{2}\t\t{3}".format(
menucar.get("m_name"),
menucar.get("m_money"),
menucar.get("user_menu_number"),
menucar.get("user_menu_money")
))
print("购物车合计:",goodsum)
while True:
print("请输入金额:",end="")
user_money = float(input())
if goodsum > user_money:
print("余额不足,请重新输入。")
else:
print("实付%f,找零%f"%(user_money,(user_money-goodsum)))
#减库存
for menucar1 in menus_car: #循环购物车中的菜品
for menu2 in menus: #循环菜单中的菜品
#获得购物车菜品名称 并 比较菜单中的菜品名称 查找是否存在
if menucar1.get("m_name") == menu2.get("m_name"):
#更新当前菜品信息中的 库存量 当前库存-购买份数
menu2.update({"m_number":menu2.get("m_number")-menucar1.get("user_menu_number")})
orders = menus_car.copy()
menus_car.clear()
break
elif num1 ==3:
while True:
print(" ")
print("----------点赞界面----------")
print("菜单名称\t\t单价\t\t份数\t\t总价\t\t点赞数")
for order in orders:
print("{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}".format(
order.get("m_name"),
order.get("m_money"),
order.get("user_menu_number"),
order.get("user_menu_money"),
order.get("m_goods"),
))
m_goods_numbers = int(input("请输入点赞数(按0退出)"))
for goods_numbers in orders: # 循环订单中的菜名
for goods_numbers_1 in menus: # 循环菜单中的菜名
if goods_numbers.get("m_name") == goods_numbers_1.get("m_name"):
goods_numbers_1.update({"m_goods": goods_numbers_1.get("m_goods")+ m_goods_numbers})
if m_goods_numbers == 0:
break
elif num1 ==4:
print(" ")
print("----------退出系统----------")
break