diff --git a/15_test_practice/01_demo.py b/15_test_practice/01_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..5f49f3e3e0f53e312593858f66dd92f1eba0f8d5 --- /dev/null +++ b/15_test_practice/01_demo.py @@ -0,0 +1,29 @@ +# 创建菜单字典 +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("无效的输入,请重新输入。") diff --git a/15_test_practice/01_demo2.py b/15_test_practice/01_demo2.py new file mode 100644 index 0000000000000000000000000000000000000000..d9c01162ddb9e2746c6d7d2805bba93f0ae9b2a6 --- /dev/null +++ b/15_test_practice/01_demo2.py @@ -0,0 +1,40 @@ +# 创建菜单字典 +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("无效的输入,请重新输入。")