#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:Caesar yang


menu = {
'湖北':{
'武汉':{
"武昌":{},
"汉口":{},
"汉阳":{}
},
'鄂州':{
'鄂城区':{},
'华容区':{},
'梁子湖区':{}
},
'孝感':{
'孝南区':{},
'孝昌区':{},
'云梦县':{}
},
},
'湖南':{
'长沙':{
'雨花区':{},
'望城区':{},
'岳麓区':{}
},
'株洲':{
'株洲':{},
'永州':{}
}

},
'浙江':{
'杭州':{
'111':{},
'222':{}
},
'绍兴':{
'绍兴市':{},
'越城区':{}
},
'嘉兴':{
'333':{}
}
}
}

exit_flag = False
while not exit_flag:
for i in menu:
print(i)
choice = input('请选择1级城市:')
if choice in menu:
while not exit_flag:
for i2 in menu[choice]:
print('\t',i2)
choice2 = input('选择2级城市:')
if choice2 in menu[choice]:
while not exit_flag:
for i3 in menu[choice][choice2]:
print('\t\t',i3)
choice3 = input('选择3级城市:')
if choice3 in menu[choice][choice2]:
while not exit_flag:
for i4 in menu[choice][choice2][choice3]:
print('\t\t\t',i4)
choice4 = input('按"b"返回上层,按"q"退出:')
if choice4 == 'b':
break
elif choice4 == 'q':
exit_flag = True
if choice3 == 'b':
break
elif choice3 == 'q':
exit_flag = True
if choice2 == 'b':
break
elif choice2 == 'q':
exit_flag = True
elif choice == 'q':
exit_flag = True



个人心得:break会跳出当前for循环,返回上一层for循环(在有while条件语句的时候)
posted on 2018-08-02 00:49  月与卿。  阅读(113)  评论(0编辑  收藏  举报