三级地名菜单

menu={
"北京":{
"朝阳":{...},
"昌平":{
"沙河":{
"老男孩":{},
"阿泰包子":{},
},
"天通苑":{...},
"回龙观":{},
},
"海淀":{...},
},
"上海":{...},
"山东":{...},
}

current_layer = menu
parent_layers =[]
while True:
for key in current_layer:
print(key)
choice = input(">>>:").strip()
if len(choice) ==0:continue
if choice in current_layer:
parent_layers.append(current_layer)
current_layer =current_layer[choice]
elif choice == "b":
if parent_layers:
current_layer = parent_layers.pop()
else:
print("无此项")
print("请重新输入")
posted @ 2018-06-07 16:09  萧白白  阅读(263)  评论(0编辑  收藏  举报