menu = { ‘北京‘: { ‘海淀‘: { ‘五道口‘: { ‘soho‘: {}, ‘网易‘: {}, ‘google‘: {} }, ‘中关村‘: { ‘爱奇艺‘: {}, ‘汽车之家‘: {}, ‘youku‘: {}, }, ‘上地‘: { ‘百度‘: {}, }, }, ‘昌平‘: { ‘沙河‘: { ‘老男孩‘: {}, ‘北航‘: {}, }, ‘天通苑‘: {}, ‘回龙观‘: {}, }, ‘朝阳‘: {}, ‘东城‘: {}, }, ‘上海‘: { ‘闵行‘: { "人民广场": { ‘炸鸡店‘: {} } }, ‘闸北‘: { ‘火车站‘: { ‘携程‘: {} } }, ‘浦东‘: {}, }, ‘山东‘: {}, } last_menu = [] current_menu = menu while True: for key in current_menu: print(key) choice = input(">:").strip() if not choice: continue if choice in current_menu: last_menu.append(current_menu) current_menu = current_menu[choice] if choice == "q": if last_menu: current_menu = last_menu.pop() else: print("已经是最顶层") if choice == "Q": current_menu = menu最多再加个输入错误重新输入。 最多也就这点代码。
原文地址:https://www.cnblogs.com/chengege/p/10816923.html
时间: 2024-10-08 11:56:42