首页 > 代码库 > 省县市三级联动
省县市三级联动
需求 省县市三级联动 用户输入河北,则打印河北省下的市,用户输入市,则显示该河北省的这个市下的县
测试信息 dic = { "河北":{ "石家庄":["鹿泉","藁城","元氏"], "邯郸":["永年","涉县","磁县"] }, "河南":{ "周口":["太康","商水","淮阳"], "郑州":["金水","二七","管城"] }, "山西":{ "太原":["迎泽","清徐","阳曲"], "大同":["阳高","天镇","灵丘"] } }
dic = { "河北":{ "石家庄":["鹿泉","藁城","元氏"], "邯郸":["永年","涉县","磁县"] }, "河南":{ "周口":["太康","商水","淮阳"], "郑州":["金水","二七","管城"] }, "山西":{ "太原":["迎泽","清徐","阳曲"], "大同":["阳高","天镇","灵丘"] } } while True: print(‘请在以下省份中选择:‘) for i in dic.keys(): print(i) pro=input(‘输入你要查询的省份(退出请按q):‘).strip().lower() if pro == ‘q‘: print(‘再见!‘) exit() if pro not in dic.keys(): print(‘要查询的省份不存在或者你的输入有误,请重新输入‘) continue else: tag=True while tag: print(‘%s有以下城市:‘ % pro) for c in dic[pro].keys(): print(c) city=input(‘请输入你要查询的城市(回到省份查找请按p,退出请按q):‘).strip().lower() if city == ‘q‘: print(‘再见!‘) exit() if city == ‘p‘: break if city not in dic[pro].keys(): print(‘要查询的城市不存在或者你的输入有误,请重新输入‘) continue else: while tag: print(‘%s有以下县区‘ % city) for cou in dic[pro][city]: print(cou) county=input(‘重新选择省份请按p,重新选择城市请按c,退出请按q:‘).strip().lower() if county == ‘q‘: print(‘再见!‘) exit() if county == ‘c‘: break if county == ‘p‘: tag=False break else: print(‘输入错误,请重新输入‘) continue
本文出自 “lyndon” 博客,请务必保留此出处http://lyndon.blog.51cto.com/11474010/1947436
省县市三级联动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。