Python Level Three Menu

Source: Internet
Author: User

Python level Three menu
    • Demand
    1. Print provincial, city, and county level three menus
    2. Can return to the upper level
    3. Can exit the program at any time

    • Code implementation
1menu = {2     'Beijing':{3         'Haidian':{4             'Five crossing':{5                 'Soho':{},6                 'NetEase':{},7                 'Google':{}8             },9             'Zhongguancun':{Ten                 'Iqiyi Art':{}, One                 'Autohome':{}, A                 'Youku':{}, -             }, -             'on the ground':{ the                 'Baidu':{}, -             }, -         }, -         'changping':{ +             'Shahe':{ -                 'old boy':{}, +                 'Beihang University':{}, A             }, at             'Tin Tong Court':{}, -             'Huilongguan':{}, -         }, -         'Chaoyang':{}, -         'Dongcheng':{}, -     }, in     'Shanghai':{ -         'Minhang':{ to             "People's square":{ +                 'Fried Chicken Shop':{} -             } the         }, *         'Zhabei':{ $             'Train Warfare':{Panax Notoginseng                 'Ctrip':{} -             } the         }, +         'Pudong':{}, A     }, the     'Hubei':{ +         'Wuhan':{ -             'Optics Valley':{}, $             'Hanzhong St.':{}, $         }, -         'Yellowstone':{ -             'Huangshigang':{}, the             'Upper Kiln':{}, -         },Wuyi         'Daye':{ the             'Mall':{}, -             'Mine Head':{}, Wu         }, -         'Huanggang':{ About             'General County':{}, $         }, -     }, - } -  ACurrent_level = Menu#record the layer of the current loop +Last_levels = []#deposit the currently entered layer into the list the  -  whileTrue: $      forKinchCurrent_level:#Loop Current Layer the         Print(k) theChoice = input ("Please enter address >>:"). Strip () the     ifChoice = ='b': the         ifLen (last_levels) = = 0: Break #The list does not have a layer record or the vertex layer exits the program -Current_level = Last_levels[-1]#when entering B, remove the previous layer when exiting inLast_levels.pop ()#when you return to the previous layer, delete the record-level the     elifChoice = ='Q':#when entering Q, exit the program the exit () About     ifChoice not inchCurrent_level:Continue theLast_levels.append (Current_level)#current layer Join record list theCurrent_level = Current_level[choice]#Add the user input layer to the current layer and loop
View Code

Python Level Three Menu

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.