三级菜单优化

# 需求:三级菜单,b返回上级,q退出

provice = {
    "四川省": {
        "成都市": {
            "金牛区": {
                "茶店子": {},
                "交大路": {}
            },
            "青羊区": {
                "光华村": {},
                "杜甫草堂": {}
            },
            "锦江区": {
                "春熙路": {}
            },
            "成华区": {
                "驷马桥": {}
            },
            "武侯区": {
                "高升桥": {},
                "红牌楼": {}
            },
            "高新区": {
                "天府软件园": {},
                "腾讯": {},
                "IBM": {}
            }
        },
        "宜宾市": {
            "翠屏区": {},
            "长宁县": {},
            "南溪区": {},
            "江安县": {}
        }
    },
    "北京市": {
        "东城区": {

        },
        "朝阳区": {

        }
    }
}

last = [provice]
current = provice

while True:
    for i in current:
        print(i)
    choice = input("input:").strip()
    if len(choice) == 0:
        continue
    if choice in current:
        last.append(current)
        current = current[choice]
    if choice == "b":
        if last:
            current = last[-1]
            last.pop()
    if choice == "q":
        break

版权声明:
作者:admin
链接:https://www.chenxie.net/archives/1624.html
来源:蜀小陈
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>