省市区小程序

#!/usr/bin/env python
#_*_coding:utf-8_*_
memu= {"北京": {"海淀": ["中关村", "四通桥"], "昌平": ["回龙观", "西二旗"]},
"上海": {"黄浦区": ["南京路", "延安路"], "静安区": ["静安街道", "石门"]}}
flag=True
sheng=''
shi=''
while flag:
if sheng!='':
if shi!='':
for key in memu[sheng][shi]:
print key
else:
for key in memu[sheng]:
print key
else:
for key in memu.keys():
print key
operation= raw_input("请输入菜单,按q退出,按b返回上一级:").strip()
if operation=="q":
print"已退出"
break
elif operation=='b':
if sheng=='':
print "已是顶级菜单"
else:
if shi=='':
sheng=''
else:
shi=''
continue
else:
if sheng=='':
sheng=operation
else:
if shi=='':
shi=operation
else:
print"已是区域菜单,请输入B返回或输入Q退出"












posted on 2016-06-07 10:20  wangqianlfxh  阅读(156)  评论(0编辑  收藏  举报