Getting started with Python-level three menu

Source: Internet
Author: User

menu = {' Beijing ': {' Haidian ': {' Five crossing ': {' Soho ': {}, ' NetEase ': {}, ' Goog            Le ': {}}, ' Zhongguancun ': {' Iqiyi ': {}, ' Autohome ': {}, ' Youku ': {},                }, ' On the ground ': {' Baidu ': {},},}, ' Changping ': {' Shahe ': {        ' Uniqlo ': {}, ' Beihang ': {},}, ' Tian Tong Yuan ': {}, ' Huilongguan ': {},}, ' Chaoyang ': {},            ' Dongcheng ': {},}, ' Shanghai ': {' Minhang ': {' People's Square ': {' Fried chicken Shop ': {}}}, ' Zhabei ': { ' Railway station ': {' Ctrip ': {}}}, ' Pudong ': {},}, ' Shandong ': {},} requirements: You can choose to go to each submenu to return from any level To the previous layer can exit the program from any level required new knowledge points: List, dictionary base version: While True:for I in Menu:print (i) Province = input ("Please select Province: (Press Q exit)") if PR Ovince = = ' Q ': Exit () else:print (' input error ') If province in Menu:while true:for I in         Menu[province]:       Print (i) City = input ("Please select the municipality: (Press Q to exit, Q to return)") If town = = ' Q ': Exit ()                 If City = = ' Q ': Break else:print (' input error ') If City in Menu[province]:                    While True:for I in menu[province][city]: print (i)                    County = input ("Please select District or county: (press Q to exit, Q to return)") if County = = ' Q ': Exit ()                    if county = = ' Q ': Break else:print (' input error ')  If county in menu[province][city]: and true:for i in Menu[province][city][county]: print (i) choice = input (' q exit, Q return:  ' If choice = = ' Q ': Exit () If choice                = = ' Q ':                Break else:print (' input error ') Loading version: Rank = Menulast_ran K = []while true:for i in Rank:print (i) Choice = input (';: '). Strip () If choice in Rank:last_r Ank.append (rank) # Add the current menu to the list rank = Rank[choice] # Go to the next level menu elif choice = = ' B ': If Len (last_ Rank)! = 0:rank = Last_rank.pop () # Deletes the last element of the list, thus returning to the previous layer elif choice = = ' Q ': Exit ()

  

Getting started with Python-level three 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.