整理

上级 2f5ec1bd
# 创建菜单字典
menu = {
1: {
"汉堡类": ["香辣鸡腿堡", "劲脆鸡腿堡", "新奥尔良烤鸡腿堡"],
},
2: {
"小食类": ["薯条", "黄金鸡块", "香甜粟米棒"],
},
3: {
"饮料类": ["可口可乐", "九珍果汁", "经典咖啡"],
},
}
while True:
try:
user_input = int(input("请输入操作数字 (0: 退出, 1: 汉堡类, 2: 小食类, 3: 饮料类): "))
if user_input == 0:
print("感谢您的使用")
break
elif user_input in menu:
menu_type = menu[user_input]
for category, items in menu_type.items():
print(category)
for item in items:
print(f"- {item}")
else:
print("无效的输入,请重新输入。")
except ValueError:
print("无效的输入,请重新输入。")
# 创建菜单字典
menu = {
1: {
"汉堡类": ["香辣鸡腿堡", "劲脆鸡腿堡", "新奥尔良烤鸡腿堡"],
},
2: {
"小食类": ["薯条", "黄金鸡块", "香甜粟米棒"],
},
3: {
"饮料类": ["可口可乐", "九珍果汁", "经典咖啡"],
},
}
while True:
user_input = input("请输入操作数字或菜名 (0: 退出, 1: 汉堡类, 2: 小食类, 3: 饮料类): ")
if user_input == '0':
print("请输入操作数字")
else:
try:
user_input = int(user_input)
if user_input in menu:
menu_type = menu[user_input]
for category, items in menu_type.items():
print(category)
for item in items:
print(f"- {item}")
else:
print("无效的输入,请重新输入。")
except ValueError:
found = False
for _, categories in menu.items():
for _, items in categories.items():
if user_input in items:
found = True
break
if found:
print("感谢您的使用")
else:
print("无效的输入,请重新输入。")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册