zoukankan      html  css  js  c++  java
  • 多级菜单(低效版)


    Readme文件:

    | -----------------------------|
    | 程序名称:三级菜单层级切换 |
    | -----------------------------|
    
    细节功能:
    1.用户输入当前层选项并回车后,进入下一层
    2.本程序总共三层
    3.每次按b可以返回上一层
    4.任何层级按q均可退出
    --------------------------------------------------------------------------------
    程序运行:
    1. 运行前需要menu.txt文件存在(即三级菜单文件,其存储格式为字典)
    2. 直接运行Task_menu程序即可
    --------------------------------------------------------------------------------
    
    #######################################
    作者:王承祥
    联系方式1:13552310609
    联系方式2:dslmoon@163.com
    我的博客:https://www.cnblogs.com/wangcx
    #######################################

    Menu文件:

    {"广州": {'天河': ['天河体育馆', '金山大夏'],'越秀': ['越秀公园', '光孝寺'],'番禺': ['长隆欢乐世界', '大夫山']},"深圳": {'福田': ['莲花山', '赛格'],'龙华': ['元山公园', '龙城广场'],'南山': ['世界之窗', '欢乐谷']},"佛山": {'禅城': ['梁园', '孔庙'],'南海': ['千灯湖', '南国桃园'],'顺德': ['清晖园', '西山庙']}}

    Task_menu文件(主程序):

    # -*-coding:utf-8-*-
    # _Author_:George
    #-----------------------------------------
    #说明:
    #1.用户输入当前层选项并回车后,进入下一层
    #2.本程序总共三层
    #3.每次按b可以返回上一层
    #4.任何层级按q均可退出
    #-----------------------------------------
    #菜单是以字典格式存储于文件中:{"广州": {'天河': ['天河体育馆', '金山大夏']}
    #-----------------------------------------
    
    
    # data = {"广州": {'天河': ['天河体育馆', '金山大夏'],
    #                     '越秀': ['越秀公园', '光孝寺'],
    #                     '番禺': ['长隆欢乐世界', '大夫山']},
    #              "深圳": {'福田': ['莲花山', '赛格'],
    #                     '龙华': ['元山公园', '龙城广场'],
    #                     '南山': ['世界之窗', '欢乐谷']},
    #              "佛山": {'禅城': ['梁园', '孔庙'],
    #                     '南海': ['千灯湖', '南国桃园'],
    #                     '顺德': ['清晖园', '西山庙']}}
    
    f1 = open("menu.txt","r",encoding="utf-8")
    menus = f1.readline()
    data = eval(menus)
    
    while True:
        print("-----Welcome to search location-----")
        for i in data:
            print(i)
        choice = input("To choose one and enter L1>>:")
        if choice in data :
            while True:
                for i2 in data[choice]:
                    print(i2)
                choice2 = input("To choose one and enter L2>>:")
                if choice2 == 'b':
                    break
                elif choice2 is not 'q':
                    print("If you want to logout, you can press 'q'.")
                else:
                    exit()
                if choice2 in data[choice]:
                    while True:
                        for i3 in data[choice][choice2]:
                            print(i3)
                        choice3 = input("Press 'b' to return last level >>:")
                        if choice3 == 'b':
                            break
                        elif choice3 is not 'q':
                            print("If you want to logout, you can press 'q'.")
                        else:
                            exit()
        elif choice is not 'q':
            print("If you want to logout, you can press 'q'.")
        else:
            exit()
  • 相关阅读:
    mysql连接数过多 解决方案
    单列模式下的数据库连接与Servlet之间页面访问用户登录的小例子
    Spring MVC理解和主要使用的注解详解
    Spring JDBC 框架中, 绑定 SQL 参数的另一种选择:具名参数(named parameter)
    xlwings
    openpyxl
    【python】Excel两表中某个信息对比
    pycharm中配置python版本问题
    python指令提示不是内部或外部命令(环境变量配置)
    python管理电脑文件及文件夹
  • 原文地址:https://www.cnblogs.com/wangcx/p/8093658.html
Copyright © 2011-2022 走看看