python 修行之路(二)(三级菜单)

#Author:Mr Li

data = {
    "嘉兴":{
        "海盐" :{"hai":{}},
        "南湖":{"nan":{}},
        "秀洲":{"xiu":{}}
    },
    "温州":{
        "平阳":{"ping":{}},
        "鹿城":{"lu":{}},
        "瓯海":{"ou":{}}
    }
}

while True:
    for i in data:
        print(i)
    choice = input("请选择:")
    if choice in data:
        while True:
            for i2 in data[choice]:
                print(i2)
            choice1 = input("请选择:")
            if choice1 in data[choice]:
                while True:
                    for i3 in data[choice][choice1]:
                        print(i3)
                        choice2 = input("请输入B:")
                    if choice2 == "B":
                        break
            if choice1 == "B":
                break
    else:
        print("no choice,please try again\n")

此代码主要练习嵌套字典,字典存储相关知识,熟悉键和值。

猜你喜欢

转载自blog.csdn.net/l_smartworld/article/details/76080021