Python Level three menu optimizer

Source: Internet
Author: User

Python Three-level menu optimizer, newbie link: http://www.cnblogs.com/xuyaping/p/6648170.html

Menu = {
' Beijing ': {
' Haidian ': {
' Five crossing ': {
' Soho ': {},
' NetEase ': {},
' Google ': {}
},
' Zhongguancun ': {
' Iqiyi art ': {},
' Autohome ': {},
' Youku ': {},
},
' On the ground ': {
' Baidu ': {},
},
},
' Changping ': {
' Shahe ': {
' Old boy ': {},
' Beihang University ': {},
},
' Tian Tong Yuan ': {},
' Huilongguan ': {},
},
' Chaoyang ': {},
' Dongcheng ': {},
},
' Shanghai ': {
' Minhang ': {
"People's Square": {
' Fried Chicken Shop ': {}
}
},
' Zhabei ': {
' Train war ': {
' Ctrip ': {}
}
},
' Pudong ': {},
},
' Shandong ': {},
}

Current_layer=menu #当前层
Last_layers=[menu] #上一层
While True:
For key in Current_layer: #打印第一层菜单
Print (key)
Choice=input (">>:"). Strip () #选择第二层菜单
If choice in Current_layer:
Last_layers.append (Current_layer) #进入下一层菜单前, add the current layer menu to the previous menu
Current_layer=current_layer[choice] #当前层菜单被重新定义, go to the loop to print the next level menu
If choice==0: #选择菜单层为空, end this cycle
Continue
If choice== "q": #选择菜单层为 "Q" to end this layer loop
Break
If choice== "B": #选择菜单层为 "B", return to the previous level menu
Current_layer=last_layers[-1] #返回上一层菜单前, the current layer is redefined
Last_layers.pop () #删除最后一次进入下一层菜单所加入的上一层列表数据
Print ("End of program! ")

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.