2-14 三级菜单
参考博客:1-2 三级菜单
参考博客:1-2 三级菜单
1.普通文艺版
# -*- coding:utf-8 -*- # 1.定义menu menu = { '北京': { '海淀': { '五道口': { 'soho': {'soho'}, '网易': {}, 'google': {} }, '中关村': { '爱奇艺': {}, '汽车之家': {}, 'youku': {}, }, '上地': { '百度': {}, }, }, '昌平': { '沙河': { '老男孩': {}, '北航': {}, }, '天通苑': {}, '回龙观': {}, }, '朝阳': {}, '东城': {}, }, '上海': { '闵行': { "人民广场": { '炸鸡店': {} } }, '闸北': { '火车战': { '携程': {} } }, '浦东': {}, }, '山东': {}, } while True: # 2.打印menu_1 for item in menu: print(item) # 3.用户输入choice choice_1 = input("请输入你的选择1 q退出 >:").strip() # 4.判断输入 if choice_1 in menu.keys(): # print('ok') while True: for item in menu[choice_1]: print('\t', item) choice_2 = input("\t请输入你的选择2 q退出|b返回 >:").strip() if choice_2 in menu[choice_1].keys(): # print('ok') while True: for item in menu[choice_1][choice_2]: print('\t', item) choice_3 = input("\t\t请输入你的选择3 q退出|b返回 >:").strip() if choice_3 in menu[choice_1][choice_2].keys(): while True: for item in menu[choice_1][choice_2][choice_3]: print('\t\t\t', item) choice_4 = input("\t\t\t请输入你的选择4 q退出|b返回 >:").strip() if choice_4 in menu[choice_1][choice_2][choice_3].keys(): while True: print('\t\t\t\t', menu[choice_1][choice_2][choice_3].get(choice_4)) choice_5 = input('\t\t\t\t你已经到底部了 q退出|b返回: ').strip() if choice_5 == 'q': print("------bye bye----") exit() elif choice_5 == 'b': break else: print("\t\t\t\t输入有误,请重新输入") elif choice_4 == 'b': break else: print("\t\t\t输入有误,请重新输入") elif choice_3 == 'q': print("------bye bye----") exit() elif choice_3 == 'b': break else: print("\t\t输入有误,请重新输入") elif choice_2 == 'q': print("------bye bye----") exit() elif choice_2 == 'b': break else: print("\t输入有误,请重新输入") elif choice_1 == 'q': print("------bye bye----") exit() else: print("输入有误,请重新输入")
2. alex装逼版本
3.alex再装逼版本
4.我的装逼版本
# -*-coding:utf-8-*- menu = { '北京': { '海淀': { '五道口': { 'soho': {}, '网易': {}, 'google': {} }, '中关村': { '爱奇艺': {}, '汽车之家': {}, 'youku': {}, }, '上地': { '百度': {}, }, }, '昌平': { '沙河': { '老男孩': {}, '北航': {}, }, '天通苑': {}, '回龙观': {}, }, '朝阳': {}, '东城': {}, }, '上海': { '闵行': { "人民广场": { '炸鸡店': {} } }, '闸北': { '火车战': { '携程': {} } }, '浦东': {}, }, '山东': {}, } next_menu = [] while True: for item in menu: print(item) choice = input("输入你的选择 q退出|b返回上一级>:").strip() if not choice: continue elif choice in menu: # print(menu[choice]) if menu[choice]: next_menu.append(menu) # print(next_menu) for testing menu = menu[choice] else: print('>>>', menu[choice]) print('你已经到底了!') elif choice == 'b': if len(next_menu) == 0: print("你已经到top了") else: # print(next_menu.pop()) for testing menu = next_menu.pop() elif choice == 'q': print("---bye bye---") exit() else: print("你输入的有误,请重新输入")