`

打印菜单(printMenu.py)

阅读更多
# 需求:
# 可依次选择进入各子菜单
# 可从任意一层往回退到上一层
# 可从任意一层退出程序
# 所需新知识点:列表、字典

# 踩分点:
# 1.只用一个while循环,且整体代码量少于15行按完成需求/条—25分
# 2.只用一个while循环,且整体代码量多于15行需求全部完成给90分
# 3.其他情况按完成需求/条—20分

menu = {
    '北京': {
        '海淀': {
            '五道口': {
                'soho': {},
                '网易': {},
                'google': {}
            },
            '中关村': {
                '爱奇艺': {},
                '汽车之家': {},
                'youku': {},
            },
            '上地': {
                '百度': {},
            },
        },
        '昌平': {
            '沙河': {
                '老男孩': {},
                '北航': {},
            },
            '天通苑': {},
            '回龙观': {},
        },
        '朝阳': {},
        '东城': {},
    },
    '上海': {
        '闵行': {
            "人民广场": {
                '炸鸡店': {}
            }
        },
        '闸北': {
            '火车站': {
                '携程': {}
            }
        },
        '浦东': {},
    },
    '山东': {},
}
path, msg = [menu], ''
while True:
    print(list(path[-1].keys()), '\t>>>' if len(msg) > 0 else '', msg)
    choice = input("输入下一级地址,退出(q),后退(b):").strip(' \t\n\r')
    if choice == 'q':
        break
    elif choice == '':
        msg = '输入不能为空!'
    elif choice == 'b':
        msg = '到顶了!' if len(path) == 1 else path.pop() and ''
    elif choice in path[-1]:
        msg = path.append(path[-1][choice]) or ''
    else:
        msg = '地址输入错误!'


不能再短(*^▽^*):
path, msg = [menu], ' '
while True:
    print(list(path[-1].keys()), '' if msg == ' ' else '\t>>>', msg)
    choice = input("输入下一级地址,退出(q),后退(b):").strip(' \t\n\r')
    if choice == 'q':
        break
    else:
        msg = (choice == '' and '输入不能为空!') \
          or (choice == 'b' and (len(path) == 1 and '到顶了!'or path.pop() and ' '))\
          or (choice in path[-1] and (path.append(path[-1][choice]) or ' ')) \
          or '地址输入错误!''
分享到:
评论

相关推荐

    原生JS打印插件之jQuery.EasyPrint.js使用文档

    原生JS打印插件之jQuery.EasyPrint.js使用文档 调用浏览器自带打印功能,使用JavaScript的 window.print(); 方法。 使用JS实现打印功能;JavaScript 实现打印操作;javascript打印大全;通用;js实现打印的方式;JS...

    python.demo.py

    print('Python %s on %s' % (sys.version, sys.platform)) sys.path.extend(['C:\\Users\\xieqianyun\\demo1', 'C:/Users/xieqianyun/demo1']) Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v....

    panic.py增强版

    经过修改过的panic.py文件 1、不必放在项目根目录,可以放在任意位置 2、product信息可以做为参数传入 ... -h print help info 详细信息参见http://liuju1234.blog.163.com/blog/static/162281520111126105523630/

    printScreen.py

    截屏用的代码,适用于windows,需要安装pywin32和pynput模块。可以随时按F12截屏(快捷键可自行修改),图片会自动保存在脚本所在文件夹,游戏和视频截屏爽歪歪~

    PrintSpooler.apk源码 (安卓内置打印apk源码)

    PrintSpooler.apk源码 (安卓内置打印apk源码),可用来参考修改或编写自己所需要的安卓usb打印

    c#报表打印VPrint源码.rar

    c#报表打印VPrint源码.rar

    c#报表打印20Print源码.rar

    c#报表打印20Print源码.rar

    c#报表打印30Print源码.rar

    c#报表打印30Print源码.rar

    Python引用(import)文件夹下的py文件的方法

    Python的import包含文件功能就跟PHP的include类似,但更确切的说应该更像是PHP中的require,因为Python里的import只要目标不存在就报错程序无法往下...print dir.b.name 执行 a.py 报错 提示找不到这个模块的名字 d

    基于jquery.print.js插件的js打印demo

    基于jquery.print.js插件的js打印demo,简单易用,使用详细教程请查看我的个人主页的博客《一款很好用的Jquery 打印插件——jQuery.print.js》

    bin2datastruct_print.py

    读取二进制bin文件,生成一个数组格式的txt文件;使用python编写;

    demo-1-print().py

    demo-1-print().py

    pidcat.py_in_ubuntu

    In order to print Android log and have class name, We often use the pidcat.py on ubuntu, This will help me sovle problem better

    print.py

    print.py

    print语句使用例子.py

    print语句使用例子.py

    tuxing_print.py

    Python中用使用列表打印..OO.OO.. .OOOOOOO. .OOOOOOO. ..OOOOO.. ...OOO... ....O....

    esp-idf-v3.2.zip

    When the build finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this automatically by running: idf.py -p PORT flash Replace PORT with the name of ...

    reader.py下载

    from __future__ import print_function import collections import tensorflow as tf import os import numpy as np def _read_words(filename): with tf.gfile.GFile(filename, "r") as f: return...

    PrintControl.cab下载

    PrintControl.cab

    对python同一个文件夹里面不同.py文件的交叉引用方法详解

    执行bb.py时,不能执行,打印错误 AttributeError: ‘module’ object has no attribute ‘a’ 原因: 如果执行bb的话,这时候bb是__main__,不是module,所以会执行到bb的from aa,这个时候python会执行aa.py,而aa...

Global site tag (gtag.js) - Google Analytics