Python beginner 13th Day Level Three menu program small job

Source: Internet
Author: User
Tags iqiyi

13day

Job Title: Level Three menu

Job Requirements:

 data structure: Menu = {' Beijing ': {' Haidian ': {' Five crossings ': {' Soho ': {}, ' NetEase                ': {}, ' Google ': {}}, ' Zhongguancun ': {' Iqiyi ': {}, ' Autohome ': {},            ' Youku ': {},}, ' on the ground ': {' Baidu ': {},},}, ' Changping ': {        ' Shahe ': {' old boy ': {}, ' Beihang ': {},}, ' Tian Tong Yuan ': {}, ' Huilongguan ': {},            }, ' Chaoyang ': {}, ' Dongcheng ': {},}, ' Shanghai ': {' Minhang ': {' People's Square ': {' Fried chicken Shop ': {} }}, ' Zhabei ': {' rail war ': {' 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 

 menu = {
' Beijing ': {
' Haidian ': {
' five crossing ': {
' Soho ': {},
' NetEase ' : {},
' Google ': {}
},
' Zhongguancun ': {
' Iqiyi ': {},
' Autohome ': {},
' Youku ': {},
},
' On the ground ': {
' Baidu ': {},
},
},
' Changping ': {
' Shahe ': {
' old boy ': {},
' Beihang ': {},
},
' Tin tong Yuan ': {},
' Huilongguan ': {},
},
' Chaoyang ': {},
' Dongcheng ': {},
},
' Shanghai ': {
' Minhang ': {
"People's Square": {
' Fried chicken Shop ': {}
}
},
' Zhabei ': {
' train war ': {
' Ctrip ': {}
}
},
' Pudong ': {},
},
' Shandong ': {},
}

Layer = Menu
Last_layer = []
While True:
For k in layer:
Print (k)
Choice = input (">>:"). Strip ()
If choice in layer:
Last_layer.append (layer) #记录父节点
Layer = Layer[choice] #更改变量
Elif Not choice:
Continue
elif Choice = = ' Q ':
If Len (Last_layer) > 0:
Layer = Last_layer.pop () #删除缓存的父节点 and returns the parent node
Else
Print ("Top Up!") ")
elif Choice = = ' Q ':
Break
Else
Print ("wrong input!") ")

Python beginner 13th Day Level Three menu program small job

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.