主要练习嵌套循环和标志位的使用方法:
#!/usr/local/python/bin/python3.6
#-*-coding:utf-8-*-
data = {
"中国":{"河北":["石家庄","廊坊","保定"],"四川":["成都","重庆","南充"],"湖北":["武汉","黄石","襄阳"]},
"美国":{"华盛顿":["芝加哥","旧金山","亚特兰大"],"纽约":["布朗克斯","国王","曼哈顿"],"德克萨斯":["休斯顿","达拉斯","圣安东尼奥"]}
}
flag = False
while not flag:
for i in data:
print(i)
choice = input("请选择:")
if choice in data:
while not flag:
for j in data[choice]:
print(j)
choice2 = input("请选择:")
if choice2 in data[choice]:
while not flag:
for k in data[choice][choice2] :
print(k)
choice3 = input("最后一层,【e】返回上一级,【q】退出:")
if choice3 == "e":
break
elif choice3 == "q":
flag = True
if choice2 == "e":
break
elif choice2 == "q":
flag = True
if choice == "q":
flag = True
共同学习,写下你的评论
评论加载中...
作者其他优质文章