Getting started with Python-level three menu

Source: Internet
Author: User

Job Title: Level Three menu

    • Job Requirements:

menu = {    'Beijing':{        'Haidian':{            'Five crossing':{                'Soho':{},                'NetEase':{},                'Google':{}            },            'Zhongguancun':{                'Iqiyi Art':{},                'Autohome':{},                'Youku':{},            },            'on the ground':{                'Baidu':{},            },        },        'changping':{            'Shahe':{                'Uniqlo':{},                'Beihang University':{},            },            'Tin Tong Court':{},            'Huilongguan':{},        },        'Chaoyang':{},        'Dongcheng':{},    },    'Shanghai':{        'Minhang':{            "People's square":{                'Fried Chicken Shop':{}            }        },        'Zhabei':{            'train station':{                'Ctrip':{}            }        },        'Pudong':{},    },    'Shandong':{},}
Requirements: You can choose to go to each submenu from any level back to the previous layer you can exit the program from any level required new knowledge points: List, dictionary

Basic version:
 whileTrue: forIinchMenu:Print(i) Province= Input ("Please select province: (press Q to exit)")    ifProvince = ='Q': Exit ()Else:        Print('Input Error')    ifProvinceinchMenu: whileTrue: forIinchMenu[province]:Print(i) City= Input ("Please select city: (Press Q to exit, Q to return)")            ifCity = ='Q': Exit ()ifCity = ='Q':                 Break            Else:                Print('Input Error')            ifCityinchMenu[province]: whileTrue: forIinchMenu[province][city]:Print(i) County= Input ("Please select a district or county: (press Q to exit, Q to return)")                    ifCounty = ='Q': Exit ()ifCounty = ='Q':                         Break                    Else:                        Print('Input Error')                    ifCountyinchMenu[province][city]: whileTrue: forIinchMenu[province][city][county]:Print(i) Choice= Input ('Q Exit, Q return:')                            ifChoice = ='Q': Exit ()ifChoice = ='Q':                                 Break                            Else:                                Print('Input Error')

Installed Force version:

Rank =Menulast_rank= [] whileTrue: forIinchrank:Print(i) Choice= Input (':'). Strip ()ifChoiceinchrank:last_rank.append (rank)#Add the current menu to the listRank = Rank[choice]#go to the next level menu    elifChoice = ='b':        ifLen (last_rank)! =0:rank= Last_rank.pop ()#deletes the last element of the list, thus returning to the previous layer    elifChoice = ='Q': Exit ()

The innermost and outermost layers can also be added to the corresponding hints.

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.