Github base 05 &三国人物查询
# 05 用户交互,显示省市县三级联动的选择. dic = { "河北": { "石家庄": ["鹿泉", "藁城", "元氏"], "邯郸": ["永年", "涉县", "磁县"], }, "河南": { "石家庄2": ["鹿泉2", "藁城2", "元氏2"], "邯郸2": ["永年2", "涉县2", "磁县2"], }, "山西": { "石家庄3": ["鹿泉3", "藁城3", "元氏3"], "邯郸3": ["永年3", "涉县3", "磁县3"], } } while True: select = input("请输入想要查询的省份") if select == '河北' or select == '河南'or select == '山西': while True: print([k for k in dic[select]]) select_2 = input("请输入想要查询的城市'q'返回上一层") if select_2 in dic[select]: print([k for k in dic[select][select_2]]) print('查询结束') break elif select_2 == 'q': break else: print('输入错误') else: print('您查找的省份不存在') continue
dic = { '魏国':{ '主公':{'曹操': ['孟德'], '曹丕': ['子桓'], '曹睿': ['元仲']}, '谋士':{'司马懿':['仲达'], '郭嘉':['奉孝'], '贾诩': ['文和']}, '武将': {'许褚': ['仲康'], '张辽':['文远'], '徐晃': ['公明']} }, '蜀国':{ '主公':{'刘备':['玄德 '],'刘禅:':['公嗣'],}, '谋士':{'诸葛亮':['孔明'],'庞统':['士元'],'徐庶':['元直']}, '武将':{'关羽':['云长'],'张飞':['翼德'],'赵云':['子龙']} }, '吴国': { '主公': {'孙权': ['仲谋 '], '孙策:': ['伯符'], '孙坚:': ['文台']}, '谋士': {'陆逊': ['伯言'], '周瑜:': ['公瑾'], '鲁肃': ['子敬']}, '武将': {'吕蒙': ['子明'], '甘宁:': ['兴霸'], '太史慈': ['子义']} } } while True: select = input("请输入想要查询的国家") if select == '魏国' or select == '蜀国'or select == '吴国': while True: print([k for k in dic[select]]) select_2 = input("请输入想要查询的职位'q'返回上一层") if select_2 in dic[select]: print([k for k in dic[select][select_2]]) select_3 = input("请输入想要查询的职位'q'返回上一层") if select_3 in dic[select][select_2]: print([k for k in dic[select][select_2][select_3]]) elif select_2 == 'q': break else: print('输入错误') else: print('您查找的国家不存在') continue