三级菜单升级版

data={
    '广东':{'广州':{'越秀','天河','花都'},
            '佛山':{'南海','禅城','顺德'},
            '珠海':{'拱门','横琴'}},
    '山东':{'济南':{},
            '滨州':{}},
    '北京':{'朝阳':{},
            '燕郊':{},
            '通州':{}}

}
import sys
current_layer=data
last_layer=[]
while True:
    for i in current_layer:
        print(i) #打印字典
    choice=input('please choice 或者b返回上级,q退出')
    if choice in current_layer:
        last_layer.append(current_layer) #存字典
        current_layer=current_layer[choice]
    elif choice =='b':
        if len(last_layer)==0:
            break
        current_layer=last_layer[-1]
        last_layer.pop()
    else:
        continue

猜你喜欢

转载自blog.csdn.net/samsonn/article/details/84717782