码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-07-28 16:44:27      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:华夏   toolbar   abs   auto   continue   author   选择   menu   bar   

# 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]

标签:华夏   toolbar   abs   auto   continue   author   选择   menu   bar   

原文地址:https://www.cnblogs.com/ftl1012/p/9382386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!