Python实例---三级菜单的实现[low]

Posted 小a玖拾柒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python实例---三级菜单的实现[low]相关的知识,希望对你有一定的参考价值。

# version: python3.2.5
# author: ‘FTL1012‘
# time: 2017/12/7 09:16

menu = {
    ‘陕西‘: {
        ‘西安‘: {
            ‘未名区‘: [‘国美‘, ‘苏宁‘, ‘京东‘],
            ‘无名区‘: [‘百度‘, ‘360 ‘, ‘搜狗‘],
            ‘优雅区‘: [‘腾讯‘, ‘默默‘, ‘订订‘]
        },
        ‘宝鸡‘: {
            ‘进队区‘: [‘word‘, ‘excel‘, ‘ppt‘],
            ‘挖第区‘: [‘华为‘, ‘锤子‘, ‘小米‘],
            ‘阿克区‘: [‘adidas‘, ‘unique‘, ‘masterbrown‘]
        },
        ‘汉中‘: {
            ‘呵呵区‘: [‘流浪‘, ‘excel‘, ‘ppt‘],
            ‘幻化区‘: [‘猥琐‘, ‘发育‘, ‘别浪‘],
            ‘三只区‘: [‘后裔‘, ‘李白‘, ‘杜甫‘]
        },
    },
    ‘山东‘: {
        ‘山东市‘: {
            ‘惠普区‘: [‘华夏‘, ‘建设‘, ‘农行‘]
        }
    },
    ‘湖南‘: {
        ‘长沙‘: {
            ‘豆腐区‘: [‘键盘‘, ‘鼠标‘, ‘显示器‘]
        }
    }
}

# print(menu[‘陕西‘][‘宝鸡‘])

flag = False

while not flag:
    print("第一级".center(50, ‘*‘))
    for k in menu:
        print(‘>>1: ‘, k)
    choice1 = input("请选择:")
    if choice1 in menu:
        print("第二级".center(50, ‘*‘))
        for key1 in menu[choice1]:
            print(‘>>2: ‘, key1)
        while not flag:
            choice2 = input("请选择:")
            if choice2 in menu[choice1]:
                print("第三级".center(50, ‘*‘))
                for key2 in menu[choice1][choice2]:
                    print(‘>>3: ‘, key2)
                while not flag:
                    choice3 = input("请选择:")
                    if choice3 in menu[choice1][choice2]:
                        print("第四级".center(50, ‘*‘))
                        for key3 in menu[choice1][choice2][choice3]:
                            print(‘>>4: ‘, key3)
                        print("最后一级了...")
                        flag = True
                    elif choice2 == ‘q‘:
                        exit(0)
                    elif choice2 == ‘b‘:
                        flag = True
                    else:
                        print("输入不合法...")
                        continue
                else:
                    flag = False
            elif choice2 == ‘q‘:
                exit(0)
            elif choice2 == ‘b‘:
                flag = True
            else:
                print("输入不合法...")
                continue
        else:
            flag = False
    elif choice1 == ‘q‘:
        exit(0)
    elif choice1 == ‘b‘:
        continue
    else:
        print("输入不合法...")
else:
    print("游戏结束...")
【稍有小bug】

以上是关于Python实例---三级菜单的实现[low]的主要内容,如果未能解决你的问题,请参考以下文章

三级菜单的实现(python程序)

Python实例---三级菜单的实现[high]

python三级菜单的实现

python---三级菜单

最Low三级菜单

python实例_三级菜单