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^ ^ 01
1 0 ^. 00.0^ ^00000 1.00.1 11
. 1 0 1^^0.01 ^^^ 01
.^ ^ 1 1^^ ^.^
1 1 0.
.. 1 ^
1 1
^ ^ .0
1 ^ 1
.. 1.1 ^0.0
^ 0 1..01^^100000..0^
1 1 ^ 1 ^^1111^ ^^
0 ^ ^ 1 1000^
.1 ^.^ . 00
.. 1.1 0. 0
1. . 1. .^
1. 1 1. ^0
^ . ^.1 00 01
^.0 001. .^
My dear Max said:
"I like you,
So the first bunch of sunshine I saw in the morning is you,
The first gentle breeze that passed through my ear is you,
The first star I see is also you.
The world I see is all your shadow."
FIGHTING FOR OUR FUTURE!!!
'''
# -*- coding: utf-8 -*-
# @ Time : 2019-8-2 13:04
# @ Author : Alex VB
# @ FileName: python_learn——Level 3 menu.py
# @ Software: PyCharm
# @ Blog :https://blog.csdn.net/weixin_43336281
menu = {
"东北" : {
"黑龙江" : {},
"吉林" : {},
"辽宁" : {},
},
"华东" : {
"上海":{},
"江苏":{},
"浙江":{},
"安徽":{},
"福建":{},
"江西":{},
"山东":{
"济南":{},
"青岛":{},
"淄博":{},
"枣庄":{},
"东营":{},
"烟台":{},
"潍坊":{},
"济宁":{},
"泰安":{},
"威海":{},
"日照":{},
"滨州":{},
"德州":{},
"聊城":{},
"临沂":{},
"菏泽":{}
},
"台湾":{},
},
"华北" : {
"北京":{},
"天津":{
"和平":{},
"河东":{},
"河西":{},
"南开":{},
"河北":{},
"红桥":{},
"滨海新":{},
"东丽":{},
"西青":{},
"津南":{},
"北辰":{},
"武清":{},
"宝坻":{},
"宁河":{},
"静海":{},
"蓟州":{},
},
"山西":{},
"河北":{},
"内蒙古":{},
},
"华中" : {
"河南":{
"郑州":{},
"开封":{},
"洛阳":{},
"平顶山":{},
"安阳":{},
"鹤壁":{},
"新乡":{},
"焦作":{},
"濮阳":{},
"许昌":{},
"漯河":{},
"三门峡":{},
"南阳":{},
"商丘":{},
"信阳":{},
"周口":{},
"驻马店":{}
},
"湖北":{},
"湖南":{},
},
"华南" : {
"广东":{},
"广西":{},
"海南":{},
"香港":{},
"澳门":{},
},
"西南" : {
"四川":{},
"贵州":{},
"云南":{},
"重庆":{},
"西藏":{},
},
"西北" : {
"陕西":{},
"甘肃":{},
"青海":{},
"宁夏":{},
"新疆":{},
},
}
Current_Layer = menu #实现动态循环
Parent_Layers = [] #保留所有父级
while True:
for key in Current_Layer:
print(key)
choice = input(">>> ").strip()
if len(choice) == 0 : continue
if choice in Current_Layer:
Parent_Layers.append(Current_Layer) #在进入下一层之前,把当前层加入到父级中
Current_Layer = Current_Layer[choice] #改变当前层
elif choice == 'back':
if Parent_Layers:
Current_Layer = Parent_Layers.pop() #取出父级列表中的最后一个值
else:print("nothing……")