#conding:utf-8 # 选做题:用户交互,显示省市县三级联动的选择 # dic = { "河北": { "石家庄": ["鹿泉", "藁城", "元氏"], "邯郸": ["永年", "涉县", "磁县"], }, "河南": { "信阳": ["光山", "固始", "新县"], "南阳": ["内乡", "社旗", "镇平"], }, "山西": { "运城": ["万泉", "荣河", "临晋", "猗氏"], "太原": ["清徐", "阳曲", "娄烦"], }, } print("默认不输入自动退出上一层") tag = True while tag: print( ‘\n‘"请选择省份:") for i in dic: print(i,end=‘ ‘) a = input(‘\n‘"开始你的表演:") if a in dic.keys(): while tag: for j in dic[a]: print(j,end=‘ ‘) b = input(‘\n‘"请选择市:") if b in dic[a].keys(): while tag: for k in dic[a][b]: print(k,end=‘ ‘) c = input(‘\n‘"请选择县:") if c in dic[a][b]: print("已经选择:",c) tag = False elif len(c) == 0: break elif c not in dic[a][b]: print("找不到这个县") elif len(b) == 0: break elif b not in dic[a].keys(): print("找不到这个市") elif len(a) == 0: tag = False elif a not in dic.keys(): print("找不到这个省份")
时间: 2024-10-13 17:38:36