Job Title: Level Three menu
menu = { 'Beijing':{ 'Haidian':{ 'Five crossing':{ 'Soho':{}, 'NetEase':{}, 'Google':{} }, 'Zhongguancun':{ 'Iqiyi Art':{}, 'Autohome':{}, 'Youku':{}, }, 'on the ground':{ 'Baidu':{}, }, }, 'changping':{ 'Shahe':{ 'Uniqlo':{}, 'Beihang University':{}, }, 'Tin Tong Court':{}, 'Huilongguan':{}, }, 'Chaoyang':{}, 'Dongcheng':{}, }, 'Shanghai':{ 'Minhang':{ "People's square":{ 'Fried Chicken Shop':{} } }, 'Zhabei':{ 'train station':{ 'Ctrip':{} } }, 'Pudong':{}, }, 'Shandong':{},}
Requirements: You can choose to go to each submenu from any level back to the previous layer you can exit the program from any level required new knowledge points: List, dictionary
Basic version:
whileTrue: forIinchMenu:Print(i) Province= Input ("Please select province: (press Q to exit)") ifProvince = ='Q': Exit ()Else: Print('Input Error') ifProvinceinchMenu: whileTrue: forIinchMenu[province]:Print(i) City= Input ("Please select city: (Press Q to exit, Q to return)") ifCity = ='Q': Exit ()ifCity = ='Q': Break Else: Print('Input Error') ifCityinchMenu[province]: whileTrue: forIinchMenu[province][city]:Print(i) County= Input ("Please select a district or county: (press Q to exit, Q to return)") ifCounty = ='Q': Exit ()ifCounty = ='Q': Break Else: Print('Input Error') ifCountyinchMenu[province][city]: whileTrue: forIinchMenu[province][city][county]:Print(i) Choice= Input ('Q Exit, Q return:') ifChoice = ='Q': Exit ()ifChoice = ='Q': Break Else: Print('Input Error')
Installed Force version:
Rank =Menulast_rank= [] whileTrue: forIinchrank:Print(i) Choice= Input (':'). Strip ()ifChoiceinchrank:last_rank.append (rank)#Add the current menu to the listRank = Rank[choice]#go to the next level menu elifChoice = ='b': ifLen (last_rank)! =0:rank= Last_rank.pop ()#deletes the last element of the list, thus returning to the previous layer elifChoice = ='Q': Exit ()
The innermost and outermost layers can also be added to the corresponding hints.
Getting started with Python-level three menu