老男孩Python 3.5学习第02周作业——三级菜单

Readme:

本程序通过字典来实现对三级菜单的逐级访问,以及逐层退回。

流程图:

1.建立字典。

2.利用while not false实现菜单重复访问,其包容性远大于while true。

3.由外向内逐步实现对其子菜单的访问。

4.通过pass命令,实现返回功能。

data = {
'辽宁省':{
'大连市':[
'甘井子区','中山区','西岗区','沙河口区 '
],
'辽阳市':[
'白塔区','文圣区','宏伟区'
]
},
'海南省':{
'文昌市':[
'文城镇','龙楼镇'
],
'海口市':[
'琼山区','秀英区','美兰区'
]
},
'天津市':{
'南开区':{},
'和平区':{},
'红桥区':{}
}
}
exit_flag = False
while not exit_flag:
for i in data:
print(i)
your_firstchoice = input('请选择省份:')
if your_firstchoice in data:
while not exit_flag:
for j in data.get(your_firstchoice):
print('\t',j)
your_secondchoice = input('请继续选择:')
if your_secondchoice in data[your_firstchoice]:
for x in data[your_firstchoice][your_secondchoice]:
print('\t\t',x)
your_thirdchoice = input('返回请按“b”')
if your_thirdchoice == 'b':
pass
elif your_thirdchoice == 'q':
exit_flag = True
if your_secondchoice == 'b':
break
elif your_secondchoice == 'q':
exit_flag = True

posted on 2018-12-24 23:55  少钧  阅读(257)  评论(0编辑  收藏  举报

导航