day2-三级菜单---改良版

Posted a10086

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day2-三级菜单---改良版相关的知识,希望对你有一定的参考价值。

再也不想看之前的low代码了。。。

 

#!/usr/bin/env python

data = {
    北京: {
        "昌平": {
            "望京1": {"奔驰", "默默"},
            "国贸2": ("cicc", "HP"),
        },
        "朝阳": {
            "望京1": {"奔驰", "默默"},
            "国贸1": ("cicc", "HP"),
        },
    },
    山东: {
        "昌平": {
            "望京1": {"奔驰", "默默"},
            "国贸2": ("cicc", "HP"),
        },
        "朝阳": {
            "望京2": {"奔驰", "默默"},
            "国贸2": ("cicc", "HP"),
        },
    },
    广东: {
        "昌平": {
            "望京1": {"奔驰", "默默"},
            "国贸2": ("cicc", "HP"),
        },
        "朝阳": {
            "望京3": {"奔驰", "默默"},
            "国贸4": ("cicc", "HP"),
        },
    },
}
current_layer = data
layerlist = list()
while True:
    for i in current_layer:
        print(i)
    choice = input("选择进入,按b返回,按q退出>>:")
    if choice in current_layer:
        try:
            layerlist.append(current_layer)
            current_layer = current_layer[choice]
        except TypeError:
            current_layer = current_layer
        continue
    elif choice.lower() == b:
        try:
            current_layer = layerlist.pop()
        except IndexError:
            pass
        continue
    elif choice.lower() == q:
        exit("bye~~")

 

以上是关于day2-三级菜单---改良版的主要内容,如果未能解决你的问题,请参考以下文章

day2-三级菜单

Python之路 day2 字典练习题之 三级菜单

python 三级菜单 while循环三次,湖北省市-县-街道的选择,3个while的循环 -day2

代码段-- 三级菜单 (基础版)

学习Python的第二十天三级菜单高级版

Python day2_17-9-11