标签:mic 循环 tin input 字典 ros 返回 soft str
#多级菜单
city = {‘湖南‘:{‘长沙‘:{‘解放路‘,‘芙蓉路‘},‘衡阳‘:{‘石鼓区‘,‘珠晖区‘}},
‘北京‘: {‘北京市‘: {‘1号‘, ‘2号‘}, ‘郊区‘: {‘3号‘, ‘4号‘}}}
print(‘输入b返回上一层‘)
back = ‘b‘
while True:
for i in city:
print(i)
choice = input(‘请输入省份:‘).strip()
if choice in city:
while True:
for j in city[choice]:
print(j)
choice2 = input(‘请输入城市‘).strip()
if choice2 == back:
break
if choice2 in city[choice]: #错误点 不能用索引判断在一个序列中
while True:
for k in city[choice][choice2]:
print(k)
choice3 = input(‘输入b,返回上一层‘).strip()
if choice3 == back:
break
else:
pass
else:
print(‘错误,请重新输入‘)
continue
else:
print(‘请重新输入‘)
continue
1.纯循环语句写的
2.不能用索引判断是否在一个字典中
标签:mic 循环 tin input 字典 ros 返回 soft str
原文地址:http://www.cnblogs.com/2bjiujiu/p/6240836.html