# encoding: utf-8
# Creator:耿亚月 Creation time:2017-1-2
# Modifier:耿亚月 Modification time:2017-1-2
#输入选择的省、市、县
def choose(data, name, level):
for i in data:
print('\t'*level,i)
choice = input('选择进入{name},按b返回》,q退出:'.format(name=name))
return choice
#输入选择是否返回上一层
def choose_back(place):
choice=input('Do you want to back to {where}? y/n:'.format(where=place))
return choice
#输入选择是否退出
def choose_exit():
choice = input('Do you want to exit? y/n:')
if choice == 'y':
return True
data = {
'北京': {
'昌平': {
'沙河': ['oldboy','test'],
'天通苑': ['链家地产','我爱我家'],
},
'朝阳': {
'望京': ['奔驰','陌陌'],
'国贸': ['CICC','HP'],
'东直门': ['Advent','飞信'],
},
'海淀': {},
},
'山东': {
'德州': {},
'青岛': {},
'济南': {},
},
'广东': {
'东莞': {},
'常熟': {},
'佛山': {},
},
}
exit_flag = False
#省
while not exit_flag:
choice = choose(data, '省', 0)
if choice in data:
#市
while not exit_flag:
choice2 = choose(data[choice], '市', 1)
if choice2 in data[choice]:
#县
while not exit_flag:
choice3 = choose(data[choice][choice2], '县', 2)
if choice3 in data[choice][choice2]:
print(data[choice][choice2][choice3])
exit_flag = True
#县
elif choice3 == 'b':
if choose_back('县') == 'y':
break
elif choice3 == 'q':
exit_flag = choose_exit()
else:
print('Invalid choice,please try again')
#市
elif choice2 == 'b':
if choose_back('省') == 'y':
break
elif choice2 == 'q':
exit_flag = choose_exit()
else:
print('Invalid choice,please try again')
#省
elif choice == 'q':
exit_flag = choose_exit()
else:
print('Invalid choice,please try again')