码迷,mamicode.com
首页 > 其他好文 > 详细

五级菜单

时间:2020-07-26 00:39:06      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:==   六盘水   print   大学   退出   color   图书馆   font   要求   

#要求:
# 打印省、市、县、镇、村五级菜单
# 可返回上一级
# 可随时退出程序

menu = {
    贵州:{
        凯里:{
            剑河:{
                革东:{},
                柳川:{},
                南哨:{
                    高定:{},
                    乌沙:{},
                    翁座:{}
                }
            },
            黎平:{
                德化:{},
                尚重:{},
                大架:{},
            },
            榕江:{
                朗洞:{},
                平江:{},
                两汪:{}
            },
        },
        遵义:{
            金沙:{
                柳塘:{},
                龙坝:{},
            },
            仁怀:{
                茅台:{}
            },
            开阳:{},
        },
        安顺:{},
        兴义:{},
        都匀:{},
        六盘水:{}
    },
    上海:{
        闵行:{
            "漕宝路":{
                金泰公寓:{},
                三佳花苑:{}
            }
        },
        徐汇:{
            徐家汇:{
                汇金百货:{}
            },
            上海体育馆:{},
            交通大学:{},
            上海图书馆:{}
        },
        静安:{},
        浦东:{},
        黄浦:{},
        普陀:{},
        松江:{},
        青浦:{},
        金山:{}
    },
    浙江:{
        杭州:{},
        金华:{},
        宁波:{},
        绍兴:{},
        嘉兴:{}
    },
}



tag=True
while tag:
    menu1=menu
    for key in menu1: # 打印第一层
        print(key)

    choice1=input(第一层>>: ).strip() # 选择第一层

    if choice1 == a: # 输入a,则返回上一级
        break
    if choice1 == b: # 输入b,则退出整体
        tag=False
        continue
    if choice1 not in menu1: # 输入内容不在menu1内,则继续输入
        continue

    while tag:
        menu_2=menu1[choice1] # 拿到choice1对应的一层字典
        for key in menu_2:
            print(key)

        choice2 = input(第二层>>: ).strip()

        if choice2 == a:
            break
        if choice2 == b:
            tag = False
            continue
        if choice2 not in menu_2:
            continue

        while tag:
            menu_3=menu_2[choice2]
            for key in menu_3:
                print(key)

            choice3 = input(第三层>>: ).strip()
            if choice3 == a:
                break
            if choice3 == b:
                tag = False
                continue
            if choice3 not in menu_3:
                continue

            while tag:
                menu_4=menu_3[choice3]
                for key in menu_4:
                    print(key)

                choice4 = input(第四层>>: ).strip()
                if choice4 == a:
                    break
                if choice4 == b:
                    tag = False
                    continue
                if choice4 not in menu_4:
                    continue

                while tag:
                    menu_5 = menu_4[choice4]
                    for key in menu_5:
                        print(key)

                    choice5 = input(第五层>>: ).strip()
                    if choice5 == a:
                        break
                    if choice5 == b:
                        tag = False
                        continue
                    if choice5 not in menu_5:
                        continue

                    while tag:
                        menu_6 = menu_5[choice5]
                        for key in menu_6:
                            print(key)

                        choice6 = input(第四层>>: ).strip()
                        if choice6 == a:
                            break
                        if choice6 == b:
                            tag = False
                            continue
                        if choice6 not in menu_6:
                            continue

        # 第六层内没数据了,无需进入下一层

 

 

五级菜单

标签:==   六盘水   print   大学   退出   color   图书馆   font   要求   

原文地址:https://www.cnblogs.com/2722127842qq-123/p/13377177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!