要求:
1、做个三级菜单
2、依次返回
思路:
1、集合
2、变量和for循环
3、依次退出
menu = {
'北京':{
'海淀':{
'五道口':{
'soho':{},
'网易':{},
'google':{}
},
'中关村':{
'爱奇艺':{},
'汽车之家':{},
'youku':{},
},
'上地':{
'百度':{},
},
},
'昌平':{
'沙河':{
'老男孩':{},
'北航':{},
},
'天通苑':{},
'回龙观':{},
},
'朝阳':{},
'东城':{},
},
'上海':{
'闵行':{
"人民广场":{
'炸鸡店':{}
}
},
'闸北':{
'火车战':{
'携程':{}
}
},
'浦东':{},
},
'山东':{},
}
current_layer = menu #定义变量
layers =[]
while True:
for i in current_layer:
print(i)
choice = input(">:").strip()
if not choice : continue
if choice in current_layer:
layers.append(current_layer)#进入下一级,保存当前层
current_layer= current_layer[choice]
elif choice == 'b':
if len(layers) != 0 :#列表不能为空
current_layer= layers.pop()#从后往前依次返回
else:
print('This is TOP !')