Python level Three menu
- Print provincial, city, and county level three menus
- Can return to the upper level
- Can exit the program at any time
1menu = {2 'Beijing':{3 'Haidian':{4 'Five crossing':{5 'Soho':{},6 'NetEase':{},7 'Google':{}8 },9 'Zhongguancun':{Ten 'Iqiyi Art':{}, One 'Autohome':{}, A 'Youku':{}, - }, - 'on the ground':{ the 'Baidu':{}, - }, - }, - 'changping':{ + 'Shahe':{ - 'old boy':{}, + 'Beihang University':{}, A }, at 'Tin Tong Court':{}, - 'Huilongguan':{}, - }, - 'Chaoyang':{}, - 'Dongcheng':{}, - }, in 'Shanghai':{ - 'Minhang':{ to "People's square":{ + 'Fried Chicken Shop':{} - } the }, * 'Zhabei':{ $ 'Train Warfare':{Panax Notoginseng 'Ctrip':{} - } the }, + 'Pudong':{}, A }, the 'Hubei':{ + 'Wuhan':{ - 'Optics Valley':{}, $ 'Hanzhong St.':{}, $ }, - 'Yellowstone':{ - 'Huangshigang':{}, the 'Upper Kiln':{}, - },Wuyi 'Daye':{ the 'Mall':{}, - 'Mine Head':{}, Wu }, - 'Huanggang':{ About 'General County':{}, $ }, - }, - } - ACurrent_level = Menu#record the layer of the current loop +Last_levels = []#deposit the currently entered layer into the list the - whileTrue: $ forKinchCurrent_level:#Loop Current Layer the Print(k) theChoice = input ("Please enter address >>:"). Strip () the ifChoice = ='b': the ifLen (last_levels) = = 0: Break #The list does not have a layer record or the vertex layer exits the program -Current_level = Last_levels[-1]#when entering B, remove the previous layer when exiting inLast_levels.pop ()#when you return to the previous layer, delete the record-level the elifChoice = ='Q':#when entering Q, exit the program the exit () About ifChoice not inchCurrent_level:Continue theLast_levels.append (Current_level)#current layer Join record list theCurrent_level = Current_level[choice]#Add the user input layer to the current layer and loopView Code
Python Level Three Menu