python三级菜单

menu = {    '北京':{        '海淀':{            '五道口':{                'soho':{},                '网易':{},                'google':{}            },            '中关村':{                '爱奇艺':{},                '汽车之家':{},                'youku':{},            },            '上地':{                '百度':{},            },        },        '昌平':{            '沙河':{                '老男孩':{},                '北航':{},            },            '天通苑':{},            '回龙观':{},        },        '朝阳':{},        '东城':{},    },    '上海':{        '闵行':{            "人民广场":{                '炸鸡店':{}            }        },        '闸北':{            '火车战':{                '携程':{}            }        },        '浦东':{},    },    '山东':{},}

登录后复制

二逼青年版:

while True:    for key in menu:        print(key)    choice = input(">>>:")    if len(choice) == 0: continue    if choice not in menu:continue    while True:        for key2 in menu[choice]:            print(key2)        choice2 = input(">>>:")        if len(choice2) == 0: continue        if choice2 == "b": break        if choice2 not in menu[choice]: continue        while True:            for key3 in menu[choice][choice2]:                print(key3)            choice3 = input(">>>:")            if len(choice3) == 0: continue            if choice3 == "b": break            if choice3 not in menu[choice][choice2]: continue            while True:                for key4 in menu[choice][choice2][choice3]:                    print(key4)                choice4 = input(">>>:")                if len(choice4) == 0: continue                if choice4 == "b": break                if choice4 not in menu[choice][choice2][choice3]: continue

登录后复制

文艺青年版:

current_level = menulast_level = []while True:    for key in current_level:        print(key)    choice = input(">>>:")    if len(choice) == 0:continue    if choice == "b":        if not last_level : break        current_level = last_level[-1]        last_level.pop()    if choice not in current_level:continue    last_level.append(current_level)    current_level = current_level[choice]

登录后复制

作者:terry
blog:http://www.cnblogs.com/kkterry/
Weibo:http://weibo.com/kkterry
E-mail:doubleginger@163.com
欢迎转载,还请标明出处!多谢多谢!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2283410.html

(0)
上一篇 2025年2月27日 20:08:02
下一篇 2025年2月26日 07:24:42

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • python杂记

    os模块说明:python os模块包含普遍的操作系统功能 os.access(path, mode) # 检验权限模式 os.chdir(path) # 改变当前工作目录os.chflags(path, flags) # 设置路径的标记为…

    编程技术 2025年2月27日
    200
  • 详解Python的装饰器

    python中的装饰器是你进入python大门的一道坎,不管你跨不跨过去它都在那里。 为什么需要装饰器 我们假设你的程序实现了say_hello()和say_goodbye()两个函数。 def say_hello():     print…

    编程技术 2025年2月27日
    200
  • Python模块:logging

    很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误、警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,logging的日志可以分为 debug、info、…

    2025年2月27日
    100
  • Python网络编程

    认识Socket socket通常也称作”套接字”,用于描述ip地址和端口,是一个通信链的句柄,应用程序通常通过”套接字”向网络发出请求或者应答网络请求。 socket起源于Unix,而Uni…

    2025年2月27日
    200
  • ROS多个master消息互通

    需求 有时候我们需要有几个不同的master, 他们之间要交换topic的内容,这时候就不能使用ros自带的设置同一个master的方法. 我们的处理方法是,构造一个client和一个server,他们运行在不同的master下面, cli…

    编程技术 2025年2月27日
    200
  • Windows版的各种Python库安装包下载地址与安装过程

    在用python开发时(windows环境),会碰到需要安装某个版本的第三方库,为了以后查找、安装方便,总结如下:   windows版的各种Python库安装包下载地址:http://www.lfd.uci.edu/~gohlke/pyt…

    2025年2月27日 编程技术
    200
  • Python内置函数id

    英文文档: id(object) Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant fo…

    编程技术 2025年2月27日
    200
  • Python魔术方法-Magic Method

    绍   在python中,所有以“__”双下划线包起来的方法,都统称为“magic method”,例如类的初始化方法 __init__ ,python中所有的魔术方法均在官方文档中有相应描述,但是对于官方的描述比较混乱而且组织比较松散。很…

    2025年2月27日 编程技术
    200
  • Python中获取当前日期的格式

    在python里如何获取当前的日期和时间呢?在python语言里,我们可以通过调用什么模块或者类函数来得到当前的时间或日期呢? 当然你可以使用时间模块(time module),该模块提供了各种和时间相关的函数。但是这个模块里的一些函数在某…

    编程技术 2025年2月27日
    200
  • 利用python2.7抓取豆瓣电影top250

    这个插件可以方便查看包括html在内许多内容 打开豆瓣电影排行榜top250网页,发现每页有25部电影,一共10页,其每一页url具有如下特征: http://movie.douban.com/top250?start=0 http://m…

    2025年2月27日
    200

发表回复

登录后才能评论