三级菜单
- 打印省、市、县三级菜单
- 可返回上一级
- 可随时退出程序
'''
{
'北京':{
"昌平":{
"沙河":["oldboy","test"],
"天通苑":["链家地产","我爱我家"]
},
"朝阳":{
"望京":["奔驰","陌陌"],
"国贸":{"CICC","HP"},
"东直门":{"Advent","飞信"},
},
"海淀":{},
},
'山东':{
"德州":{},
"青岛":{},
"济南":{}
},
'广东':{
"东莞":{},
"常熟":{},
"佛山":{},
},
}
'''
#!/usr/bin/env python
# coding: utf-8
# Author: Yerban
data = {
'北京': {
"昌平": {
"沙河": ["oldboy", "test"],
"天通苑": ["链家地产", "我爱我家"]
},
"朝阳": {
"望京": ["奔驰", "陌陌"],
"国贸": {"CICC", "HP"},
"东直门": {"Advent", "飞信"},
},
"海淀": {},
},
'山东': {
"德州": {},
"青岛": {},
"济南": {}
},
'广东': {
"东莞": {},
"常熟": {},
"佛山": {},
},
}
# 标志位,只要不为True,就会一直循环
exit_flag = False
while not exit_flag:
for a in data:
print(a)
user_choice1 = input("选择省份>>>:")
if user_choice1 in data:
while not exit_flag:
for b in data[user_choice1]:
print("\t", b)
user_choice2 = input("选择地区>>>:")
if user_choice2 in data[user_choice1]:
while not exit_flag:
for c in data[user_choice1][user_choice2]:
print("\t\t", c)
user_choice3 = input("选择地标>>>:")
if user_choice3 in data[user_choice1][user_choice2]:
# 方法一
# while True:
# for d in data[user_choice1][user_choice2][user_choice3]:
# print("\t\t\t", d)
# user_choice4 = input("已经到底了,请输入'q'返回!>>>:")
# if user_choice4 == "q":
# break
# 方法二
for d in data[user_choice1][user_choice2][user_choice3]:
print("\t\t\t", d)
user_choice4 = input("已经到底了,请输入'b'返回!>>>:")
if user_choice4 == "b":
pass # 占位跳过
elif user_choice4 == "q":
exit_flag = True
if user_choice3 == "b":
break
elif user_choice3 == "q":
exit_flag = True
if user_choice2 == "b":
break
elif user_choice2 == "q":
exit_flag = True
if user_choice1 == "b":
break
elif user_choice1 == "q":
exit_flag = True