三级菜单(2)优化

来源:互联网 发布:淘宝店铺手机怎么激活 编辑:程序博客网 时间:2024/05/22 12:10

优化

# -*- coding: utf-8 -*- # @Author: oppend# @Date:   2017-07-29 23:56:31# @Last Modified by:   oppend# @Last Modified time: 2017-07-30 00:10:18menu = {"北京":{"北京市":{"东城区":{4},                        "西城区":{4},                        "朝阳区":{4},                        "丰台区":{4}                        }                },        "天津":{"天津市":{"和平区":{4},                        "河东区":{4},                        "河西区":{4},                        "南开区":{4},                        "河北区":{4}                        },                "经开区":{"经开西区":{4},                        "经开东区":{4}                        }                }        }current_layer = menuparrent_layer = []while True:    for layer in current_layer:        print(layer)    choice = input('current:')    if choice in current_layer:        parrent_layer.append(current_layer)        current_layer = current_layer[choice]    elif choice == 'b':        if parrent_layer:            current_layer = parrent_layer.pop()    elif choice == 'q':        break    else:        print('不存在')
原创粉丝点击