python 三级菜单
province_list = { "华南":{ "广东":["广州市","佛山市","深圳市","东莞市"], "广西":["南宁市","柳州市","桂林市","北海市"], "海南":["海口市","三亚市","三沙市","儋州市"] }, "华东":{ "上海":["黄浦区","卢湾区","徐汇区","长宁区","普陀区"], "安徽":["合肥市","芜湖市","淮南市","马鞍山市"], "江苏":["南京市","无锡市","徐州市","常州市","苏州市"] }, "华北":{ "北京":["东城区","西城区","朝阳区","丰台区","石景山区","海淀区"], "山西":["太原市","大同市","阳泉市","长治市"], "河北":["石家庄市","唐山市","秦皇岛市","邢台市"] }, "华中":{ "湖北":["武汉市","黄石市","十堰市","十堰市"], "河南":["郑州市","开封市","洛阳市","平顶山市"], "湖南":["长沙市","株洲市","衡阳市","邵阳市"] }, "西南":{ "重庆":["万州区","涪陵区","渝中区","大渡口区"], "四川":["成都市","自贡市","攀枝花市","德阳市"], "贵州":["贵阳市","六盘水市","遵义市","安顺市"], }, "特别行政区":{ "香港":["屯门","弯仔","北角","西贡"], "澳门":["花地玛堂区","圣安多尼堂区","大堂区","望德堂区"], }, } judge = True while judge : judge1 = True judge2 = True print('省列表:') for i in province_list: print(i) user_input = input('请输入所显示的省名称选择查看对象,退出按Q,返回按B:') while judge1: if user_input in province_list : print(user_input+'省市列表:') for x in province_list[user_input] : print(x) user_input1 = input ('请输入所显示的市名称选择查看对象,退出按Q,返回按B:') while judge2: if user_input1 in province_list[user_input] : print(user_input + '市县列表:') for y in province_list[user_input][user_input1]: print(y) user_input2 = input('以到达最底层县级名称,没有下一级菜单,退出按Q,返回按B:') if user_input2.upper() == 'Q': judge1 = False judge = False break elif user_input2.upper() == 'B': print('已返回上一层菜单。') break else: user_input2 = input('您的输入有误,以到达最底层县级名称,没有下一级菜单,退出请按Q,返回请按B!') elif user_input1.upper() == 'Q': judge1 = False judge = False break elif user_input1.upper() == 'B': print('已返回上一层菜单。') judge1 = False break else: user_input1 = input('您的输入有误,请输入所显示的市名称选择查看对象,退出按Q,返回按B:') elif user_input.upper() == 'Q' : judge = False break elif user_input.upper() == 'B' : user_input = input('已经是最高层菜单,请输入省名进行选择,退出请按Q,返回请按B:') else : user_input = input('您的输入有误,请输入省名进行选择,退出请按Q,返回请按B:') print('关闭程序')