首页 > 其他 > 详细

三级菜单

时间:2018-12-17 17:56:53      阅读:144      评论:0      收藏:0      [点我收藏+]

三级标题

while循环实现三级菜单

技术分享图片
# -*- coding: utf-8 -*-
#__author__:Selid
#__date__:2018/12/13

menu_all={
    甘肃省:{
        兰州市:{
            城关区:{},
            七里河区:{},
            安宁区:{},
            西固区:{},
            榆中县:{},
            永登县:{}
        },
        天水市:{
            秦州区:{},
            秦安县:{},
            甘谷县:{},
            武山县:{},
            张家川县:{},
        },
        武威市:{
            古浪县:{},
            凉州区:{},
            民勤县:{},
            天祝县:{},
        },
        张掖市:{
            甘州区:{},
            高台县:{},
            民乐县:{},
            临泽县:{},
        },
    },
    陕西省:{
        西安市:{
            新城区:{},
            莲湖区:{},
            莲湖区:{},
            未央区:{},
            雁塔区:{},
            灞桥区:{},
            阎良区:{},
            阎良区:{},
            长安区:{},
        },
        宝鸡市:{
            秦都区:{},
            渭城区:{},
            长武县:{},
            淳化县:{},
            旬邑县:{},
        },
        铜川市:{
            临渭区:{},
            华州区:{},
            大荔县:{},
            合阳县:{},
        },
        延安市:{
            宝塔区:{},
            按赛区:{},
            延长线:{},
            延川县:{},
        },

    }

}

parent_layers=[]
carrent_layer=menu_all

while True:
    for key in carrent_layer:
        print key
    choice=input(>>>).strip()
    if len(choice)==0:continue
    if choice in carrent_layer:
        parent_layers.append(carrent_layer)
        carrent_layer=carrent_layer[choice]
    elif choice==b:
        if parent_layers:
            carrent_layer=parent_layers.pop()
    else:print 无此项
else:
    print programes exited
View Code

 

三级菜单

原文:https://www.cnblogs.com/selid/p/10132829.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!