. 1 MENU = { 2 ' Beijing ' : { 3 ' Haidian ' : { 4 ' Wudaokou ' : { . 5 ' SOHO ' : {}, . 6 ' YORK ' : {}, . 7 ' Google ' : {} . 8 }, . 9 ' Zhongguancun ' : { 10 ' iQIYI ' : {}, 11 ' car home ' : {}, 12 ' All Time Youku ':{}, 13 }, 14 ' on the ground ' : { 15 ' Baidu ' : {} 16 } 17 } 18 ' Changping ' : { 19 ' River ' : { 20 ' old boys ' : {}, 21 ' Northern ' : {} 22 } 23 ' Tiantongyuan ' : {}, 24 ' huilongguan ' : {} 25 } 26 'Sunny' : {}, 27 ' East ' : {} 28 } 29 ' Shanghai ' : { 30 ' minhang ' : { 31 , " People's Square " : { 32 ' Fried Chicken ' : {} 33 } 34 } 35 ' Zhabei ' : { 36 ' station ' : { 37 ' Cheng ' : {} 38 } 39 }, 40 'Pudong ' : {} 41 } 42 ' Shandong ' : {} 43 } 44 is 45 ' '' 46 1 may be sequentially selected for each sub-menu to enter the variables do dictionary # 2, for circulating Key 47 2. from recede back layer of any layer selected INPUT # 48 3 # can exit the program from any one exits the loop 49 '' ' 50 51 is c_menu = MENU # current dictionary current = C 52 is p_menu = [] # by list storing the dictionary information, Previous P = 53 is the while True: 54 is # cycles dictionary list print Key 55 for Key in c_menu: 56 is Print (Key) 57 is Choice = INPUT ( " >>>: " ). .strip () Lower () # waits for user input to remove all lower rear space to facilitate identification 58 IF Choice in c_menu: # the next level 59 p_menu.append (c_menu) # add to the list of the current layer 60 c_menu = c_menu [choice] # current layer becomes the choice of selecting the next layer 61 is elif choice == " B " : 62 is IF p_menu: 63 is c_menu p_menu = [-1] # taken from the list to the last value, i.e., the circulating level, assigned to current_menu 64 p_menu.pop () # After deleting, keeping a list of error does not return to the upper 65 elif Choice == " q " : BREAK # If you enter q, the program ends. 66 the else : 67 Print ( ' error message, please choose again ' .center (50, ' * ' )) 68 IF not c_menu: 69 Print ( ' there is no information, press B to return: ' )