首页 > 代码库 > week 1--三级菜单
week 1--三级菜单
zone = {
"内蒙":{
"包头":["东河区","昆都仑区","青山区","九原区"],
"呼和浩特":["新城区","回民区","玉泉区","赛罕区"],
"鄂尔多斯":["东胜区","准格尔旗","达拉特旗","伊金霍洛旗"],
"通辽":["科尔沁区","开鲁县","库伦旗","奈曼旗"],
"呼伦贝尔":["海拉尔区","满洲里","扎兰屯","牙克石"]
},
"北京":{
"东城区":["东华门","景山街","交道口","安定门"],
"西城区":["长安街","什刹海","天桥","月坛"],
"朝阳区":["三里屯","呼家楼","和平里","劲松"],
"丰台区":["右安门","太平桥","大红门","南苑"],
"石景山区":["八宝山","老山","古城","八角"]
},
"吉林":{
"长春":["南关区","宽城区","九台区","二道区"],
"吉林":["昌邑区","龙潭区","船营区","丰满区"],
"四平市":["铁西区","铁东区","公主岭","双辽"],
"辽源":["龙山区","西安区","东丰县","东辽县"],
"通化市":["东昌区","二道江区","梅河口","通化县"]
},
"辽宁":{
"沈阳":["和平区","沈河区","大东区","皇姑区"],
"大连":["中山区","西岗区","沙河口区","金州区"],
"鞍山":["铁西区","铁东区","立山区","千山区"],
"抚顺":["新抚区","东洲区","望花区","抚顺县"],
"本溪":["平山区","溪湖区","明山区","南芬区"]
}
}
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
for province in zone:#遍历字典的key,列出省份名称
print(province)
print("=====================================")
province_flag = True#跳出循环标签
while province_flag:
for i in range(3):#指定循环3次,循环3次,退出
province_input = input("请输入省份名称 : ")
if province_input.strip() in zone.keys():#检查输入省份名称是否在字典中
print("城市信息 : ")
print("=====================================")
for city in zone[province_input].keys():#遍历字典的key,列出城市名称
print(city)
print("=====================================")
city_flag = True#跳出循环标签
while city_flag:
for j in range (3):#指定循环3次,循环3次,跳出循环
city_input = input("请输入城市名称 : ")
if city_input.strip() in zone[province_input].keys():#检查输入城市名称是否在字典中
print("区县信息 : ")
print("=====================================")
for area in zone[province_input][city_input]:#遍历字典的key,列出区县名称
print(area)
print("=====================================")
area_flag = True#跳出循环标签
while area_flag:
for k in range (3):#指定循环3次,循环3次,跳出循环
area_input = input("请输入区县名称 : ")
if area_input.strip() in zone[province_input][city_input]:#检查输入城市名称是否在字典中
print("=====================================")
print("您所查询的信息 : ",province_input,city_input,area_input)
print("=====================================")
province_flag = False#跳出循环
city_flag = False#跳出循环
exit()#跳出外循环
else:
if k!=2:
print("输入区县名称有误,请重新输入。。。 还有 %d 次机会。。。"%(2-k))
print("=====================================")
for area in zone[province_input][city_input]:#列出区县名称,方便重新输入
print(area)
print("=====================================")
if k==2:
print("输入错误三次,请重新输入城市名称。。。")
print("=====================================")
for city in zone[province_input].keys():#列出城市名称,方便重新输入
print(city)
print("=====================================")
area_flag = False#跳出循环
else:
if j!=2:
print("输入城市名称有误,请重新输入。。。 还有 %d 次机会。。。"%(2-j))
print("=====================================")
for city in zone[province_input].keys():#列出城市名称,方便重新输入
print(city)
print("=====================================")
if j==2:
print("输入错误三次,请重新输入省份名称。。。")
print("=====================================")
for province in zone:#列出省份名称,方便重新输入
print(province)
print("=====================================")
city_flag = False
else:
if i!=2:
print("输入省份名称有误,请重新输入。。。 还有 %d 次机会。。。"%(2-i))
print("=====================================")
for province in zone:#列出省份名称,方便重新输入
print(province)
print("=====================================")
if i==2:
print("输入错误三次,退出。。。")
province_flag = False
week 1--三级菜单
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。