博客
关于我
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/

你可能感兴趣的文章
Progress Kemp LoadMaster 远程命令执行漏洞复现(CVE-2024-1212)
查看>>
Project configuration is not up-to-date with pom.xml. Run Maven->Update Project
查看>>
Project Euler 15 Lattice paths
查看>>
Project Euler 48 Self powers( 大数求余 )
查看>>
Project Euler Problem 12: Highly divisible triangular number
查看>>
ProjectEuler 2
查看>>
projection介绍及EPSG:4326和EPSG:3857的投射转换
查看>>
project打开文件时,显示无法识别此文件格式?
查看>>
Prometheus + Grafana on Kubernetes部署
查看>>
prometheus + grafana进行服务器资源监控
查看>>
Prometheus Alertmanager 告警配置详解
查看>>
Prometheus Grafana 展示平台
查看>>
Prometheus pushgateway使用详解
查看>>
Prometheus 云原生 - Prometheus 数据模型、Metrics 指标类型、Exporter 相关
查看>>
Prometheus 云原生 - 基于 file_sd、http_sd 实现 Service Discovery
查看>>
Prometheus 云原生 - 微服务监控报警系统 (Promethus、Grafana、Node_Exporter)部署、简单使用
查看>>
Prometheus 云原生 - 监控 Linux、MySQL、Redis、RabbitMQ、Docker、SpringBoot 3.x
查看>>
Prometheus 介绍
查看>>
Prometheus 安全配置详解
查看>>
prometheus 安装node_exporter, node_exporter 安装最新版 普罗米修思安装监控服务器client
查看>>