需求:
- 三级菜单
- 可依次选择进入各子菜单
# Author: Mr.Xue
# 2019.10.21
data = {
'浙江': {
'台州': {
'玉环': ['沙门', '楚门', '凯门'],
'温岭': ['岙环', '三门']
},
'宁波': {
'镇海': {},
'鄞州': {}
},
'杭州': {}
},
'北京': {
'朝阳': {},
'临平': {}
},
'广东': {}
}
exit_flag = False
while not exit_flag:
for i in data:
print(i)
choice = input("选择进入1('q'退出): ")
if choice in data:
while not exit_flag:
for j in data[choice]:
print('\t', j)
choice2 = input("\t选择进入2(按'b'返回上一级, 'q'退出): ")
if choice2 == 'q':
exit_flag = True
elif choice2 == 'b':
break
if choice2 in data:
while not exit_flag:
for k in data[choice][choice2]:
print('\t\t', k)
choice3 = input("\t\t选择进入3(按'b'返回上一级, 'q'退出): ")
if choice3 == 'q':
exit_flag = True
elif choice3 == 'b':
break
if choice3 in data:
while not exit_flag:
for x in data[choice][choice2][choice3]:
print('\t\t\t', x)
choice4 = input("\t\t\t选择'q'退出或者选择'b'返回上一级: ")
if choice4 == 'q':
exit_flag = True
elif choice4 == 'b':
break