多级菜单(低效版)


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()

 

posted on 2017-12-23 16:14  承祥君  阅读(157)  评论(0编辑  收藏  举报

导航