Python's Multilevel menu

Source: Internet
Author: User

Requirements:

    1. Level three Menu
    2. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.