python3.5------三级菜单
笔者QQ :360212316
逻辑图
代码
city = { "华南": { "广东": ["广州市", "佛山市", "深圳市", "东莞市"], "广西": ["南宁市", "柳州市", "桂林市", "北海市"], "海南": ["海口市", "三亚市", "三沙市", "儋州市"] }, "华东": { "上海": ["黄浦区", "卢湾区", "徐汇区", "长宁区", "普陀区"], "安徽": ["合肥市", "芜湖市", "淮南市", "马鞍山市"], "江苏": ["南京市", "无锡市", "徐州市", "常州市", "苏州市"], "浙江": ["杭州市", "宁波市", "温州市", "湖州市", "绍兴市"] }, "华北": { "北京": ["东城区", "西城区", "朝阳区", "丰台区", "石景山区", "海淀区"], "山西": ["太原市", "大同市", "阳泉市", "长治市"], "河北": ["石家庄市", "唐山市", "秦皇岛市", "邢台市"], "天津": ["武清区", "河东区", "河西区", "南开区"] }, "华中": { "湖北": ["武汉市", "黄石市", "十堰市", "十堰市"], "河南": ["郑州市", "开封市", "洛阳市", "平顶山市"], "湖南": ["长沙市", "株洲市", "衡阳市", "邵阳市"] }, "西南": { "重庆": ["万州区", "涪陵区", "渝中区", "大渡口区"], "四川": ["成都市", "自贡市", "攀枝花市", "德阳市"], "贵州": ["贵阳市", "六盘水市", "遵义市", "安顺市"], }, "特别行政区": { "香港": ["屯门", "弯仔", "北角", "西贡"], "澳门": ["花地玛堂区", "圣安多尼堂区", "大堂区", "望德堂区"], }, } while True: for i in city: print(i) user_chose = input("选择地区:") if user_chose in city: while True: for i_1 in city[user_chose]: print(i_1) user_chose_1 = input("选择省份:") if user_chose_1 in city[user_chose]: while True: for i_2 in city[user_chose][user_chose_1]: print(i_2) user_chose_2 = input("\33[31;1m最后一层,输入b返回,输入q退出\033[0m:") if user_chose_2 == 'b': break elif user_chose_2 == 'q': exit() else: print("\33[31;1m选项不存在,请重新输入\033[0m") elif user_chose_1 == 'b': break elif user_chose_1 == 'q': exit() else: print("\33[31;1m选项不存在,请重新输入\033[0m") elif user_chose == 'b': break elif user_chose == 'q': exit() else: print("\33[31;1m选项不存在,请重新输入\033[0m")