标签:highlight 小白 while == not 作用 int python 清华大学
---恢复内容开始---
#!/usr/bin/python
# -*- coding:utf-8 -*-
# Author:zhaosj
# 创建一个地区(area)字典
Area = {
‘北京‘:{
‘丰台区‘:{
"右安门街道":[‘小明‘,‘小丽‘,‘小红‘],
"太平桥街道":[‘小王‘,‘小号‘,‘小白‘],
"西罗园街道":[‘小恒‘,‘小朱‘,‘小杨‘],
"大红门街道":[‘小树‘,‘小青‘,‘小晴‘],
"南苑街道":[‘小平‘,‘小童‘,‘小天‘]
},
‘海淀区‘:{
"羊坊店街道":[‘北京大学‘,"清华大学","北京师范大学"],
"甘家口街道":[‘人民大学‘,"北京体育大学","北京邮电大学"],
"八里庄街道":[‘鸟巢‘,"水立方","国家体育馆"],
"紫竹院街道":[‘新东方‘,‘紫竹影院‘,‘金鼎大厦‘],
"北下关街道":[‘北航‘,‘北理工‘,‘北工业‘]
},
‘昌平区‘:{
"城北街道":[‘‘], # 未完待完善
"南口地区":[‘‘],
"马池口地区":[‘‘],
"沙河地区":[‘小汤山‘,‘老牛湾‘,‘史各庄‘],
"城南街道":[‘‘]
},
‘朝阳区‘:{
"朝外街道":[‘‘],
"劲松街道":[‘‘],
"建外街道":[‘‘],
"呼家楼街道":[‘‘],
"八里庄街道":[‘‘]
},
‘大兴区‘:{},
‘通州区‘:{},
‘东城区‘:{},
‘西城区‘:{}
},
‘河北‘:{},
‘山东‘:{},
‘河南‘:{},
‘山西‘:{}
}
exit_entry = False # 定义变量,变量值等于False(假)
while not exit_entry: # while 循环,当不等于exit_entry时
for i in Area:
print(i)
choice = input("选择进入第一层>>>:")
if choice in Area:
while not exit_entry:
for i2 in Area[choice]:
print("\t",i2)
choice2 = input("选择进入第二层>>>:")
if choice2 in Area[choice]:
while not exit_entry:
for i3 in Area[choice][choice2]:
print("\t\t",i3)
choice3 = input("选择进入第三层>>>:")
if choice3 in Area[choice][choice2]:
for i4 in Area[choice][choice2][choice3]: # 因为没有第4层,当输入这一层时,打印以上三层信息
print("\t\t",i4)
choice4 = input("已经是最后一层了,按b返回>>>:")
if choice4 == "b":
#break # 终止所有循环
pass # 占位符作用
elif choice4 == "q":
exit_entry = True
if choice3 == "b":
break
elif choice3 == "q":
exit_entry = True
if choice2 == "b":
break
elif choice2 == "q":
exit_entry = True
---恢复内容结束---
标签:highlight 小白 while == not 作用 int python 清华大学
原文地址:http://www.cnblogs.com/eedweek/p/6816366.html