Three-level menu, based on the number selected by the user, into the sub-menu. First-level presentation.
1menu = {2 'Beijing': {3 "Chaoyang": {4 "CBD": ['CICC','CCTV'],5 "Jinrongjie": ["CT"],6 "Wangjing": ["Momo","Chuizi"]7 },8 "Haidian": ['Baidu','Youku']9 },Ten 'Shanghai': { One "Pudong": ["Ctrip"," One Shop"], A "Puxi": ["China Bank","America Bank"] - } - } theExit_flag =False - while notExit_flag: - forIndex, keyinchEnumerate (Menu.keys ()): - Print(index, key) +Choice_1 = input ("Choose menu to enter:"). Strip () - ifchoice_1.isdigit (): +Choice_1 =Int (choice_1) A atKey_1 =list (Menu.keys ()) [Choice_1] - while notExit_flag: - forIndex, keyinchEnumerate (menu[key_1]): - Print(' -', index, key) -choice_2 = input ("Choose menu to enter:"). Strip () - ifchoice_2.isdigit (): inchoice_2 =Int (choice_2) - toKey_2 =list (Menu[key_1].keys ()) [choice_2] + while notExit_flag: - forIndex, keyinchEnumerate (menu[key_1][key_2]): the Print('-->-->', index, key) *Choice_3 = input ("Choose menu to enter:"). Strip () $ ifchoice_3.isdigit ():Panax Notoginseng Print(" the ...") - elifChoice_3 = ='quit': theExit_flag =True + elifChoice_3 = =' Back': A Break the Else: + Print("====going to quit====")View Code
Note: This version is Python3.0 version
Python's three-tier menu