Simple exercise: Python Level three menu optimizer

Source: Internet
Author: User

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':{ -                 'Beihang University':{}, +             }, A             'Tin Tong Court':{}, at             'Huilongguan':{}, -         }, -         'Chaoyang':{}, -         'Dongcheng':{}, -     }, -     'Shanghai':{ in         'Minhang':{ -             "People's square":{ to                 'Fried Chicken Shop':{} +             } -         }, the         'Zhabei':{ *             'Train Warfare':{ $                 'Ctrip':{}Panax Notoginseng             } -         }, the         'Pudong':{}, +     }, A     'Shandong':{}, the}

The code is as follows:

1Current_layer=menu#Current Layer2Last_layers=[menu]#up a layer3  whileTrue:4      forKeyinchCurrent_layer:#Print the first level menu5         Print(Key)6Choice=input (">>:"). Strip ()#Select the second level menu7     ifChoiceinchCurrent_layer:8Last_layers.append (Current_layer)#Add the current layer menu to the previous menu before entering the next level menu9Current_layer=current_layer[choice]#The current layer menu is redefined and enters the loop to print the next level menuTen     ifChoice==0:#Select menu layer is empty, end this loop One         Continue A     ifchoice=="Q":#Select the menu layer as "Q" to end this layer loop -          Break -     ifchoice=="b":#Select the menu layer as "B" to return to the previous level menu theCURRENT_LAYER=LAST_LAYERS[-1]#The current layer is redefined before returning to the previous layer menu -Last_layers.pop ()#deletes the last layer of list data added to the next level of menu entry - Print("The program is over! ") -     

Simple exercise: Python Level three menu optimizer

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.