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