zoukankan      html  css  js  c++  java
  • python系统学习:第三周之简单的三级菜单

    # 三级目录
    info = {
    # 一级
    'ShanXi': {
    # 二级
    'JieXiu': {
    # 三级
    'XiaoSongQv': ['Burn here!'],
    'SanSchool': ['Study here']
    }
    },
    'BeiJing': {
    'ChaoYang': {
    'XianNinghou': ['Live here!']
    },
    'BeiYuan': {
    'TieJian': ['Work Here!']
    }
    }
    }
    # 三级目录的跳转
    # 定义标志
    flag = False
    while not flag:
    for name1 in info:
    print(name1)
    # 选择1
    choice = input('>>where?')
    # 判断是否存在
    if choice in info:
    # 判断成功打印第二层
    while not flag:
    for name2 in info[choice]:
    print(name2)
    # 选择
    choice2 = input('>>where?')
    # 判断是否存在
    if choice2 in info[choice]:
    # 判断成功打印第三层
    while not flag:
    for name3 in info[choice][choice2]:
    print(name3)
    choice3 = input('>>where?')
    if choice3 in info[choice][choice2]:
    for name4 in info[choice][choice2][choice3]:
    print(name4)
    choice4 = input('最后一层,b返回,q退出!')
    if choice4 == 'b':
    pass # 占位符 我什么都不做
    elif choice4 == 'q':
    flag = True
    elif choice3 == 'b':
    break
    elif choice3 == 'q':
    flag = True
    elif choice2 == 'b':
    break
    elif choice2 == 'q':
    flag = True
    # 输入B返回
    elif choice == 'b':
    pass
    # 输入q退出
    elif choice == 'q':
    flag = True

      或许你认为这个写法比较弱智,但是学习代码都是从麻烦到简单,学会了最原始的写法,能更好的了解运行机制,等后面学了函数等,就变得简单了。

  • 相关阅读:
    TCP/IP讲解
    Android开发的技术层次
    页面右下角弹出类似QQ或MSN的消息提示
    C# winform 自定义鼠标图标
    C#遍历指定文件夹中的所有文件
    C#操作Word
    关于数据绑定的一些小技巧
    Silverlight遍历本地文件夹
    ckeditor+ckfinder+syntaxhighlight实现上传和插入代码高亮(for .NET)
    wpf 动画效果
  • 原文地址:https://www.cnblogs.com/niushichong/p/10009133.html
Copyright © 2011-2022 走看看