标签:else append current inpu data input == 上海 int
data = {
‘北京‘: {
‘朝阳‘: {},
‘海淀‘: {},
‘昌平‘: {},
},
‘上海‘: {},
‘四川‘: {
‘广元‘:{
‘利州区‘:{},
‘昭化‘:{},
‘朝天三区‘:{},
},
‘成都‘:{
‘金牛区‘: {},
‘成华区‘: {},
‘高新区‘: {},
},
‘绵阳‘:{
‘涪城区‘: {},
‘游仙区‘: {},
‘农科区‘: {},
},
},
}
current_layer = data
parent_layers = []
while True:
for i in current_layer: #循环字典中的key
print(i)
choice = input(‘请输入:‘)
if choice in current_layer:
parent_layers.append(current_layer)
current_layer = current_layer[choice]
elif choice == ‘b‘:
if parent_layers:
current_layer = parent_layers.pop()
elif choice == ‘q‘:
current_layer = data
elif choice == ‘e‘:
exit()
else:
print(‘您的输入有误,请重新输入:‘)
标签:else append current inpu data input == 上海 int
原文地址:http://www.cnblogs.com/zhangyuxin/p/7700816.html