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

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

时间:2018-06-28 01:01:54      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:ror   代码   app   append   exit   list()   for   菜单   end   

再也不想看之前的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-三级菜单---改良版

标签:ror   代码   app   append   exit   list()   for   菜单   end   

原文地址:https://www.cnblogs.com/a10086/p/9236671.html

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