博客
关于我
Python进阶实战之三级菜单
阅读量:441 次
发布时间:2019-03-06

本文共 3204 字,大约阅读时间需要 10 分钟。

Python从入门到放弃完整教程目录

一、Python进阶实战之三级菜单

1.1 面条版
menu = {    '北京': {        '海淀': {            '五道口': {                'soho': {},                '网易': {},                'google': {}            },            '中关村': {                '爱奇艺': {},                '汽车之家': {},                'youku': {}            },            '上地': {                '百度': {}            },        },        '昌平': {            '沙河': {                '老男孩': {},                '北航': {}            },            '天通苑': {},            '回龙观': {},        },        '朝阳': {},        '东城': {},    },    '上海': {        '闵行': {            "人民广场": {                '炸鸡店': {}            }        },        '闸北': {            '火车战': {                '携程': {}            }        },        '浦东': {},    },    '山东': {},}tag = Truewhile tag:    menu1 = menu    for key in menu1:        print(key)    choice1 = input('第一层>>: ').strip()    if choice1 == 'b':        break    if choice1 == 'q':        tag = False        continue    if choice1 not in menu1:        continue    while tag:        menu_2 = menu1[choice1]        for key in menu_2:            print(key)        choice2 = input('第二层>>: ').strip()        if choice2 == 'b':            break        if choice2 == 'q':            tag = False            continue        if choice2 not in menu_2:            continue        while tag:            menu_3 = menu_2[choice2]            for key in menu_3:                print(key)            choice3 = input('第三层>>: ').strip()            if choice3 == 'b':                break            if choice3 == 'q':                tag = False                continue            if choice3 not in menu_3:                continue            while tag:                menu_4 = menu_3[choice3]                for key in menu_4:                    print(key)                choice4 = input('第四层>>: ').strip()                if choice4 == 'b':                    break                if choice4 == 'q':                    tag = False                    continue                if choice4 not in menu_4:                    continue
1.2 文艺青年版
menu = {    '北京': {        '海淀': {            '五道口': {                'soho': {},                '网易': {},                'google': {}            },            '中关村': {                '爱奇艺': {},                '汽车之家': {},                'youku': {}            },            '上地': {                '百度': {}            },        },        '昌平': {            '沙河': {                '老男孩': {},                '北航': {}            },            '天通苑': {},            '回龙观': {},        },        '朝阳': {},        '东城': {},    },    '上海': {        '闵行': {            "人民广场": {                '炸鸡店': {}            }        },        '闸北': {            '火车战': {                '携程': {}            }        },        '浦东': {},    },    '山东': {},}# part1(初步实现):能够一层一层进入layers = [menu]while True:    if len(layers) == 0:        break    current_layer = layers[-1]    for key in current_layer:        print(key)    choice = input('>>: ').strip()    if choice == 'q':        break    if choice not in current_layer:        continue    layers.append(current_layer[choice])

2.0 测试流程图

  • 北京上海山东>>: 背景
  • 北京上海山东>>: 上海闵行闸北浦东
  • 浦东>>: q
  • 北京上海山东>>: q

转载地址:http://pbgyz.baihongyu.com/

你可能感兴趣的文章
python ctypes库中动态链接库加载方式
查看>>
python datetime笔记
查看>>
python day10
查看>>
python file
查看>>
Python FileDialog获取文件夹路径不是文件
查看>>
python filter过滤器的使用_python基础知识分享:zip()、filter函数和reduce如何使用?...
查看>>
python flask 请求code 400, message Bad request version
查看>>
Python Flink Stateful函数入口上的Kafka键访问
查看>>
Python float - str - 浮动怪异
查看>>
Python Flower库:分布式任务管理与监控
查看>>
Python for 循环和迭代器行为
查看>>
Python For循环多次返回
查看>>
python frame_python3 selenium自动化 frame表单嵌套的切换方法
查看>>
Python ftplib - 指定端口
查看>>
Python furl库:一键搞定复杂URL操作
查看>>
Python GC 也会关闭文件吗?
查看>>
python gen_key.py 报错 提示找不到OpenSSL lib
查看>>
python getattrribute_Python学习——面向对象高级之反射
查看>>
Python进阶语法:字典推导式
查看>>
python gil_Python中GIL的使用详解
查看>>