Python 實例3—三級菜單
阿新 • • 發佈:2018-01-12
百度 for pytho body span pre log elif 愛奇藝
老男孩培訓學習:
1 ‘‘‘ 2 Author:Ranxf 3 ‘‘‘ 4 menu = { 5 ‘北京‘: { 6 ‘海澱‘: { 7 ‘五道口‘: { 8 ‘soho‘: {}, 9 ‘網易‘: {}, 10 ‘google‘: {} 11 }, 12 ‘中關村‘: { 13 ‘愛奇藝‘: {}, 14 ‘汽車之家‘: {},15 ‘youku‘: {}, 16 }, 17 ‘上地‘: { 18 ‘百度‘: {}, 19 }, 20 }, 21 ‘昌平‘: { 22 ‘沙河‘: { 23 ‘老男孩‘: {}, 24 ‘北航‘: {}, 25 }, 26 ‘天通苑‘: {}, 27 ‘回龍觀‘: {},28 }, 29 ‘朝陽‘: {}, 30 ‘東城‘: {}, 31 }, 32 ‘上海‘: { 33 ‘閔行‘: { 34 "人民廣場": { 35 ‘炸雞店‘: {} 36 } 37 }, 38 ‘閘北‘: { 39 ‘火車戰‘: { 40 ‘攜程‘: {} 41 } 42 }, 43 ‘浦東‘: {}, 44 }, 45 ‘山東‘: {}, 46 } 47 exit_flag = False 48 49 while not exit_flag: 50 for i1 in menu: 51 print(i1) 52 53 choice1 = input(">>>選擇一級菜單1>>>: ") 54 if choice1 in menu: 55 while not exit_flag: 56 for i2 in menu[choice1]: 57 print("\t", i2) 58 59 choice2 = input(">>>選擇二級菜單2>>>: ") 60 if choice2 in menu[choice1]: 61 while not exit_flag: 62 for i3 in menu[choice1][choice2]: 63 print("\t\t", i3) 64 65 choice3 = input(">>>選擇三級菜單3>>>: ") 66 if choice3 in menu[choice1][choice2]: 67 for i4 in menu[choice1][choice2][choice3]: 68 print("\t\t", i4) 69 choice4 = input(">>>最後一級菜單,按b返回,按q退出>>>: ") 70 if choice4 == ‘b‘: 71 pass 72 elif choice1 == ‘q‘: 73 exit_flag = True 74 75 if choice3 == ‘b‘: 76 break 77 elif choice3 == ‘q‘: 78 exit_flag = True 79 80 if choice2 == ‘b‘: 81 break 82 elif choice2 == ‘q‘: 83 exit_flag = True 84 if choice1 == ‘b‘: 85 break 86 elif choice1 == ‘q‘: 87 exit_flag = True
Python 實例3—三級菜單