Requirements:
- Level three Menu
- You can select to go to each submenu in turn
Flowchart Follow-up re-replenishment
The code is as follows:
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #Author Jiang4 5menu={6 'Shaanxi':{7 'Xian':['Wild Goose Pagoda','Terracotta Warriors'],8 'Baoji':['Dharma Temple','Yun Taishan'],9 'Hanzhong':['Qingmuchuan','Wuhou Shrine'],Ten }, One 'Shanxi':{ A 'Taiyuan':['Jin Ci','Pure Yang Palace'], - 'Datong':['Hengshan','ISKCON temple'], - 'Linfen':['Hukou Waterfall','Cheonbuldong'], the }, - 'Hunan':{ - 'Changsha':['Yuelu Shan','Orange Chau'], - 'Zhuzhou':['Shen Nong Gu','Emperor Yan Mausoleum'], + 'Hengyang':['Hengshan','Water Curtain Cave'], - }, + } A atprovince_list=list (Menu.keys ()) - whileTrue: - forIndex,keyinchEnumerate (Menu.keys (), 1): - Print('Province', Index,key) -Pro_id=input ('Please enter the province number, or enter Q to exit:') - ifpro_id.isdigit (): inPro_id=Int (pro_id) - ifPro_id>0 andpro_id<=Len (province_list): toPro_name=province_list[pro_id-1] +city_list=list (Menu[pro_name].keys ()) - whileTrue: the forJinchcity_list: * Print('City', City_list.index (j) +1, J) $City_id=input ('Please enter the city number, or enter B to return to the parent menu, or enter Q to exit:')Panax Notoginseng ifcity_id.isdigit (): -City_id=Int (city_id) the ifCity_id>0 andcity_id<=Len (city_list): +City_name=city_list[city_id-1] Aview_list=Menu[pro_name][city_name] the whileTrue: + forIinchview_list: - Print('Attractions', View_list.index (i) +1, i) $View_id=input ('Please enter the attraction number, or enter B to return to the parent menu, or enter Q to exit:') $ ifview_id=='b': - Break - elifview_id=='Q': the exit () - Else:Wuyi Print('Input not qualified') the Else: - Print('the user%d you entered does not exist'%city_id) Wu elifcity_id=='b': - Break About elifcity_id=='Q': $ exit () - Else: - Print('Input not qualified') - Else: A Print('the user%d you entered does not exist'%pro_id) + elifpro_id=='Q': the exit () - Else: $ Print('Input not qualified')
Python's Multilevel menu