foods_list = [
{"NO":1,"name":"开水白菜","¥":568},
{"NO":2,"name":"东坡肉","¥":398},
{"NO":3,"name":"佛跳墙","¥":999},
{"NO":4,"name":"罐焖三宝鸭","¥":299},
{"NO":5,"name":"红花鱼翅捞饭","¥":688},
{"NO":6,"name":"乌鱼蛋汤","¥":688},
{"NO":7,"name":"狮子头","¥":566}
]
vip_list = [{"name":"111","password":"1234","余额":1000},
{"name":"222","password":"1234","余额":800},
{"name":"张三","password":"1234","余额":600}]
user_food = []
user1 = []
#点餐
def order_food():
user_order = input("""
欢迎您的光临 请点餐
1.开水白菜:568
2.东坡肉:398
3.佛跳墙:999
4.罐焖三宝鸭:299
5.红花鱼翅捞饭:688
6.乌鱼蛋汤:688
7.狮子头:566
8.返回主菜单
""")
try:
int(user_order)
except:
print("编号错误 请重新输入")
return order_food()
user_order = int(user_order)
for i in foods_list:
if i["NO"] == user_order:
for j in user_food:
if user_order == j["NO"]:
pd1 = input("此菜已经在您的菜单里了 输入1继续添加 输入2取消点菜")
try:
int(pd1)
except:
print("编号错误 请重新输入")
return order_food()
pd1 = int(pd1)
if pd1 == 1:
user_food.append(i)
print("点菜成功 %s已经添加到您的菜单中" % i["name"])
return order_food()
elif pd1 == 2:
print("已经取消 请继续点菜")
return order_food()
else:
print("编号错误 请重新选择")
return order_food()
else:
user_food.append(i)
print("点菜成功 %s已经添加到您的菜单中" % i["name"])
return order_food()
elif user_order == 8:
print("已退出 请继续")
return guanyumenu()
print("编号错误 请重新输入")
return order_food()
#取消点餐
def def_food():
if user_food == []:
print("没有菜品 请先点餐")
return order_food()
else:
for i in user_food:
print(i)
del1 = input("请输入要取消的菜系序号")
for j in user_food:
try:
int(del1)
except:
return def_food()
del1 = int(del1)
if j["NO"] == del1:
user_food.remove(j)
print("取消成功 您现在的菜单为:")
for i in user_food:
print(i)
guanyumenu()
print("无此菜品")
return def_food()
#确认订单
def enter_food():
print("您现在的订单为:")
for i in user_food:
print(i)
# print("您现在的订单为%s"%user_food)
guanyumenu()
#结账
def check_out():
print("结账")
sum1 = 0
global user_food
for i in user_food:
sum1 = sum1 + i["¥"]
if sum1 == 0:
print("没有菜品 请先点餐")
return order_food()
else:
print("结账:总金额为%d" % sum1)
if user1["余额"] >= sum1:
user1["余额"] = user1["余额"] - sum1
print("结账成功 您的余额为%d元"%user1["余额"])
else:
buzu1 = input("""
您的余额不足 是否进行充值或刷卡
1-充值
2-主菜单
""")
try:
int(buzu1)
except:
print("输入有误")
return " "
buzu1 = int(buzu1)
if buzu1 == 1:
add_money()
elif buzu1 == 2:
menu()
else:
print("输入有误 返回主页")
return " "
# for j in user1:
# print(user1)
# user_money = j
# user_money = int(user_money)
# if user_money < sum1:
# print("余额不足 支付失败")
# check_out()
# else:
# zero = user_money - sum1
# del user_food
# print("支付成功 找您%s元"%zero)
return menu()
def guanyumenu():
user1 = input("""
1.点餐
2.取消点餐
3.确认订单
4.充值
5.结账
6.退出
""")
try:
int(user1)
except:
print("请输入正确的编号")
return guanyumenu()
user1 = int(user1)
if user1 == 1:
order_food()
elif user1 == 2:
def_food()
elif user1 == 3:
enter_food()
elif user1 == 4:
add_money()
elif user1 == 5:
check_out()
elif user1 == 6:
menu()
else:
print("请输入正确的编号")
return guanyumenu()
#菜单
def menu():
user11 = input("""
欢迎来到紫光阁五星级国际饭店 请进行操作
1.进入系统
2.退出
""")
try:
int(user11)
except:
print("请输入正确的编号")
return menu()
user11 = int(user11)
if user11 == 1:
guanyumenu()
elif user11 == 2:
print("已退出 期待您的下次光临")
return False
else:
print("请输入正确的编号")
return menu()
def login():
denglu1 = input("""
******************
请选择您要进行的选项
1.登录
2.注册
******************
""")
try:
int(denglu1)
except:
print("输入有误")
login()
denglu1 = int(denglu1)
if denglu1 == 1:
panduan()
elif denglu1 == 2:
zhuce()
else:
print("请输入正确的选项")
return login()
def panduan():
name = input("请输入您的用户名")
if name == '':
print("用户名不能为空 请重新输入")
return panduan()
for u in vip_list:
if name == u["name"]:
for i in range(3):
pwd = input("请输入您的密码")
if u["password"] == pwd:
print("校验成功")
global user1
user1 = u
return menu()
else:
print("密码输入错误 请重新输入")
print("输入错误已超三次 账户*")
return login()
print("用户不存在 请先注册")
return login()
def zhuce():
name1 = input("请输入您的账号")
password1 = input("请输入您的密码")
new = {"name": name1, "password": password1, "余额": 0}
vip_list.append(new)
print("注册成功")
login()
def add_money():
print("您正在进行充值")
num_money = input("请输入金额")
try:
int(num_money)
except:
print("请输入正确的金额")
return False
num_money = int(num_money)
if num_money > 0:
user1["余额"] = user1["余额"] + int(num_money)
print(user1['name'], "存款成功,余额%d" % user1["余额"])
guanyumenu()
else:
print("请输入正确的金额")
guanyumenu()
if __name__ == '__main__':
login()