#多级菜单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(‘请重新输入‘) continue1.纯循环语句写的2.不能用索引判断是否在一个字典中
时间: 2024-10-11 03:17:18