zoukankan      html  css  js  c++  java
  • 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】
  • 相关阅读:
    mysql中给查询结果添加序号
    Mysql如何取当日的数据
    nginx 出现413 Request Entity Too Large问题的解决方法
    Mac 安装Jupyter Notebook
    Python-用xlrd模块读取excel,数字都是浮点型,日期格式是数字的解决办法
    sql-exists、not exists的用法
    sql语句replace函数的使用
    Python-日期格式化
    Python-自动用0补取长度
    Flask-实现下载功能
  • 原文地址:https://www.cnblogs.com/ftl1012/p/9382386.html
Copyright © 2011-2022 走看看