Python语言学习:homework2

三级菜单

# Author:Crystal
data = {
    '北京':{
        "昌平":{
            "沙河":["oldbay","test"],
            "天通苑":["连捷地产","我爱我家"]
        },
        "朝阳":{
            "望京":["宝马","奔驰"],
            "国贸":{"HP","CP"},
            "东直门":{"费心","Advent"}
        },
        "海淀":{}
    },
    '山东':{
        "德州":{},
        "青岛":{},
        "济南":{}
    },
    '广东':{
        "东莞":{},
        "常熟":{},
        "佛山":{}
    },
}
exit_flag=False
while not exit_flag:
    for i in data:
        print(i)         #打印第一层,L1
    choice = input("选择进入1>>:")     #用户输入
    if choice in data:              #判断输入的值是否在data中
        while not exit_flag:
            for i2 in data[choice]:
                print("\t",i2)            #打印第二层,L2
            choice2 = input("选择进入2>>:")
            if choice2 in data[choice]:     #判断输入的值是否在data[choice]中
                while not exit_flag:
                    for i3 in data[choice][choice2]:
                        print("\t\t",i3)     #打印第三层,L3
                    choice3 = input("选择进入3>>:")
                    if choice3 in data[choice][choice2]:    #判断输入的值是否在data[choice][choice2]中
                        for i4 in data[choice][choice2][choice3]:
                            print("\t\t",i4)      #打印第四层,L4
                        choice4 = input("最后一层,按b返回>>:")
                        if choice4 == 'b':
                            pass       #pass的作用是占位符
                        elif choice4 == 'q':
                            exit_flag = True    #判断是否退出,如退出设置exit_flag为true
                    if choice3 == 'b':
                        break
                    elif choice3 == 'q':
                        exit_flag = True     #判断是否退出,如退出设置exit_flag为true
            if choice2 == 'b':
                break
            elif choice2 == 'q':
                exit_flag = True    #判断是否退出,如退出设置exit_flag为true

  

posted @ 2020-02-15 11:24  黑球西西  阅读(157)  评论(0编辑  收藏  举报