Python program 3--level three menu program

Source: Internet
Author: User

Program: Level Three Menu

Requirements:

    1. Print provincial, city, and county level three menus
    2. Can return to the upper level
    3. Can exit the program at any time
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     'Shandong':{}, + } -  $Exit_flag = True#set a pointer that jumps out of the entire loop $  -  whileExit_flag:#If you want to keep in this menu, you have to use the dead loop directly; -     #If there are several loops inside, then the existing knowledge can only set an outside variable to set the exit condition the      forIinchMenu#show the current level of content -         Print(i)Wuyi  theChoice1 = input ('Please enter the province, exit please enter Q') -  Wu     ifChoice1inchMenu: -         #This is the first floor of the province . About          whileExit_flag: $              forI2inchMenu[choice1]: -                 Print(I2) -Choice2 = input ('Please enter the area, B is the previous layer, Q is the exit') -             ifChoice2inchMenu[choice1]: A                 #This is the first floor of the district . +                  whileExit_flag: the                      fori3inchMenu[choice1][choice2]: -                         Print(i3) $Choice3 = input ('Please enter a location, B is the previous layer, Q is the exit') the                     ifChoice3inchMenu[choice1][choice2]: the                         #This is the bottom . the                          whileExit_flag: the                             ifi3inchMenu[choice1][choice2][choice3]: -                                 Print(i3) in                             Print("This is the last floor .") theChoice4 = input ('Select B, or Q') the                             ifChoice4 = ="b": About                                  Break the                             elifChoice4 = ="Q": theExit_flag =False the                                  Break         #here must remember break, so exit_flag can take effect, jump out of the entire cycle +                             Else: -                                 Print('your input was wrong.') the                                  Break               #You must remember to quit here .Bayi                     elifChoice3 = ="b": the                          Break the                     elifChoice3 = ="Q": -Exit_flag =False -                          Break  #here must remember break, so exit_flag can take effect, jump out of the entire cycle the                     Else: the                         Print('your input was wrong.') the                          Break  #You must remember to quit here . the             elifChoice2 = ="b":#elif can be used together so that multiple layers of nested if are avoided.  -                  Break the             elifChoice2 = ="Q": theExit_flag =False the                  Break  #here must remember break, so exit_flag can take effect, jump out of the entire cycle94             Else: the                 Print('your input was wrong.') the                  Break  #You must remember to quit here . the     elifChoice1 = ="b":98          Break About     elifChoice1 = ="Q": -Exit_flag =False101          Break  #here must remember break, so exit_flag can take effect, jump out of the entire cycle102     Else:103         Print('your input was wrong.')104          Break  #You must remember to quit here . the 106      Break

Written like this feeling is still quite low, the following more than 20 lines of code is copied.

Python program 3--level three menu program

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.