pytho实现三级菜单
third_menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家':{}, 'youku':{}, }, '上地':{ '百度':{}, }, }, '昌平':{ '沙河':{ '老男孩':{}, '北航':{}, }, '天通苑':{}, '回龙观':{}, }, '朝阳':{}, '东城':{}, }, '上海':{ '闵行':{ "人民广场":{ '炸鸡店':{} } }, '闸北':{ '火车战':{ '携程':{} } }, '浦东':{}, }, '山东':{}, }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
flag = False while not flag: for i in third_menu: print(i) choice1 = input("请选择一级菜单:") if choice1 in third_menu: while not flag: for i in third_menu[choice1]: print("\t",i) choice2 = input("请选择二级菜单:") if choice2 in third_menu[choice1]: while not flag: for i2 in third_menu[choice1][choice2]: print("\t\t",i2) choice3 = input("请输入三级菜单:") if choice3 in third_menu[choice1][choice2]: for i3 in third_menu[choice1][choice2][choice3]: print("\t\t\t",i3) choice4 = input("最后一层,按b返回上一层:") if choice4 == "b": pass elif choice4 == "q": flag = True if choice3 == "b": break elif choice3=="q": flag = True if choice2 == "b": break elif choice2 == "q": flag = True elif choice1 =="q": flag = True