标签:
#!/usr/bin/env python
#author:lei
import collections
Break = [‘b‘]
dic = {
‘北京‘:
{‘海淀区‘:[‘中关村‘,‘亚运村‘,‘清华‘,‘北大‘],
‘东城区‘:[‘东单‘,‘北京站‘,‘朝阳门‘,‘银河soho‘]},
‘上海‘:
{‘黄浦区‘:[‘黄埔1‘,‘黄埔2‘,‘黄埔3‘,‘黄埔4‘],
‘浦东区‘:[‘浦东1‘,‘浦东2‘,‘浦东3‘,‘浦东4‘]}
}
order_dic = collections.OrderedDict(sorted(dic.items()))
for k,v in enumerate(order_dic.keys()):
print (k+1,v)
#break_flag = False
while True:
break_flag = False
input_num = input("请输入二级菜单,输入q退出,输入b退出到上一级: ").strip()
if len(input_num) ==0:continue
if input_num in Break:break
if input_num ==‘q‘:
break_flag = True
break
new_input_num = int(input_num) -1
if new_input_num <=1:
key1 = sorted(dic.keys())[new_input_num]
for k1,v1 in enumerate(dic[key1]):
print (k1+1,v1)
else:
continue
while True:
input_num_2 = input("请输入三级菜单序号,输入q退出,输入b退出到上一级: ").strip()
if len(input_num_2) ==0:continue
if input_num_2 in Break:break
if input_num_2 ==‘q‘:
break_flag = True
break
new_input_num_2 = int(input_num_2) -1
if new_input_num_2 <=1:
key2 = sorted(dic[key1].keys())[new_input_num_2]
for k2,v2 in enumerate(dic[key1][key2]):
print (k2+1,v2)
else:
continue
if break_flag is True:
break
else:
continue
标签:
原文地址:http://www.cnblogs.com/zl-py/p/5485395.html