首页 > 代码库 > 简陋三级交互
简陋三级交互
#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("找不到这个省份")
简陋三级交互
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。