标签:int map -- home 武汉 菜单 city 字典 需要
city_map = {
"湖北":{"武汉":["武昌","汉阳","汉口"],
"黄冈":["黄州","红安","麻城"]},
"吉林":{"长春":["高新区","南关区"],
"四平":["东区","西区"]}
} #定义一个字典
print ("--------地图--------")
for i in city_map: #遍历字典的key,列出省市的名字
print(" ",i)
print ("-------------------")
for i in range(3):
city_name =input("请输入你要查询的省\n")
if city_name in city_map:
sheng_name = city_map[city_name]
print ("%s省包含以下区"%city_name)
for x in sheng_name:
print (x)
shi_name = sheng_name.keys()
shi_name_input = input("请输入需要查询的市")
if shi_name_input in shi_name:
quxian_name = city_map[city_name][shi_name_input]
print("%s包含的区名有:"%shi_name_input)
for k in quxian_name:
print(k)
exit()
else:
print("输入错误")
pass
else:
print("输入错误")
pass
else:
print("输入超过三次,结束")
老男孩python_12期_第一天_homework_三级菜单
标签:int map -- home 武汉 菜单 city 字典 需要
原文地址:http://www.cnblogs.com/andyIoI/p/6369153.html