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