• python三级菜单


    #作者:刘亮辉
    #时间:2019/3/7

    #打印三级菜单
    #定义一个字典:
    '''定义一个三级菜单'''
    mnue = {
    '北京':{
    '朝阳':{
    '朝阳1':{},
    '朝阳2':{},
    '朝阳3':{},
    },
    '丰台':{
    '丰台1':{},
    '丰台2':{},
    '丰台3':{},
    },
    '通州':{
    '通州1':{},
    '通州2':{},
    '通州3':{},
    },
    },
    '河南':{
    '郑州':{
    '郑州1':{},
    '郑州2':{},
    '郑州3':{},
    },
    '洛阳':{
    '洛阳1':{},
    '洛阳2':{},
    '洛阳3':{},
    },
    '周口':{
    '周口1':{},
    '周口2':{},
    '周口3':{},
    },
    },
    '上海':{
    '上海1':{},
    '上海2':{},
    '上海3':{},
    },
    }

    '''''''''''''''''''''打印'''''''''''''''''''''''''''''''''
    #定义一个标志位
    back_flag = False
    exit_flag = False
    #1。先循环打印第一级菜单:
    while not back_flag:
    for key in mnue:
    print(key)
    choice1 = input('1》》》》》:').strip()
    #2.根据输入的数据,打印第二级菜单:
    if choice1 in mnue:
    #3.让打印停留在当前级:
    while not back_flag and not exit_flag:
    for key2 in mnue[choice1]:
    print(key2)
    choice2 = input('2》》》》').strip()
    if choice2 == 'a':
    back_flag = True
    if choice2 == 'q':
    exit_flag = True
    if choice2 in mnue[choice1]:
    while not back_flag and not exit_flag:
    for key3 in mnue[choice1][choice2]:
    print(key3)
    choice3 = input('3>>>>>>>>').strip()
    if choice3 == 'a':
    back_flag = True
    if choice3 == 'q':
    exit_flag = True
    if choice3 in mnue[choice1][choice2]:
    while not back_flag and not exit_flag:
    for key4 in mnue[choice1][choice2][choice3]:
    print(key4)
    print('已经是最后一层了')
    choice4 = input('如果返回上一层,请输入a')
    if choice4 == 'a':
    back_flag = True
    if choice4 == 'q':
    exit_flag = True
    else:
    back_flag = False
    else:
    back_flag = False
    else:
    back_flag = False



    方法二:
      
    mnue = {
    '北京':{
    '朝阳':{
    '朝阳1':{},
    '朝阳2':{},
    '朝阳3':{},
    },
    '丰台':{
    '丰台1':{},
    '丰台2':{},
    '丰台3':{},
    },
    '通州':{
    '通州1':{},
    '通州2':{},
    '通州3':{},
    },
    },
    '河南':{
    '郑州':{
    '郑州1':{},
    '郑州2':{},
    '郑州3':{},
    },
    '洛阳':{
    '洛阳1':{},
    '洛阳2':{},
    '洛阳3':{},
    },
    '周口':{
    '周口1':{},
    '周口2':{},
    '周口3':{},
    },
    },
    '上海':{
    '上海1':{},
    '上海2':{},
    '上海3':{},
    },
    }
    current_lary = mnue
    current_list = []
    while True:
    for key in current_lary:
    print(key)
    choice = input("请输入所选项")
    if len(choice) == 0:
    continue
    if choice in current_lary:
    current_list.append(current_lary)
    current_lary = current_lary[choice]
    elif choice == 'b':
    if current_list:
    current_lary = current_list.pop()
    else:
    print("结束")













  • 相关阅读:
    查看git submodule更改
    /var/lib/docker空间占用过大迁移
    docker -修改容器
    docker重命名镜像repository和tag
    方法的重写、重载。
    方法的声明与使用。
    二维数组。
    标准输入输出流概述和输出语句。
    冒泡排序法。
    IO流,对象操作流优化。
  • 原文地址:https://www.cnblogs.com/liulianghui/p/10492762.html
Copyright © 2020-2023  润新知