博客
关于我
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中*args 和**kwargs的用法
查看>>
Python中*args和**kwargs的使用
查看>>
python中0、1、True、False、if条件
查看>>
python中argparse模块关于 parse_args() 函数详解(全)
查看>>
python中base64编码与解码
查看>>
python中break怎么用_详解Python中break语句的用法
查看>>
python中del函数的垃圾回收
查看>>
Python中DrissionPage的详细解析与实战
查看>>
python中enumerate、变量类型转换
查看>>
python中execute是啥_python – 为什么“c.execute(…)”打破循环?
查看>>
python中exit和break区别_Python中exit()和sys.exit()之间的区别
查看>>
python中h5的用法
查看>>
python中http协议编程_HTTP编程
查看>>
python中import os_Python:相对导入与绝对导入(import)、os.path、__file__
查看>>
python中is和==操作符
查看>>
Python中range对象的使用以及打印九九乘法表
查看>>
Python中set.discard和set.remove方法之间的运行时差异?
查看>>
python中tkinter中value_输入字段中的python Tkinter get()值
查看>>
Python中wx.FlexGridSizer
查看>>
Python中xPath技术和BeautifulSoup的使用
查看>>