>  기사  >  백엔드 개발  >  Python 3단계 메뉴

Python 3단계 메뉴

高洛峰
高洛峰원래의
2016-10-29 11:36:031369검색

menu = {
    '北京':{
        '海淀':{
            '五道口':{
                'soho':{},
                '网易':{},
                'google':{}
            },
            '中关村':{
                '爱奇艺':{},
                '汽车之家':{},
                'youku':{},
            },
            '上地':{
                '百度':{},
            },
        },
        '昌平':{
            '沙河':{
                '老男孩':{},
                '北航':{},
            },
            '天通苑':{},
            '回龙观':{},
        },
        '朝阳':{},
        '东城':{},
    },
    '上海':{
        '闵行':{
            "人民广场":{
                '炸鸡店':{}
            }
        },
        '闸北':{
            '火车战':{
                '携程':{}
            }
        },
        '浦东':{},
    },
    '山东':{},
}

얼비 청소년판:

while True:
    for key in menu:
        print(key)
    choice = input(">>>:")
    if len(choice) == 0: continue
    if choice not in menu:continue
    while True:
        for key2 in menu[choice]:
            print(key2)
        choice2 = input(">>>:")
        if len(choice2) == 0: continue
        if choice2 == "b": break
        if choice2 not in menu[choice]: continue
        while True:
            for key3 in menu[choice][choice2]:
                print(key3)
            choice3 = input(">>>:")
            if len(choice3) == 0: continue
            if choice3 == "b": break
            if choice3 not in menu[choice][choice2]: continue
            while True:
                for key4 in menu[choice][choice2][choice3]:
                    print(key4)
                choice4 = input(">>>:")
                if len(choice4) == 0: continue
                if choice4 == "b": break
                if choice4 not in menu[choice][choice2][choice3]: continue

문학 청소년판:

current_level = menu
last_level = []
while True:
    for key in current_level:
        print(key)
    choice = input(">>>:")
    if len(choice) == 0:continue
    if choice == "b":
        if not last_level : break
        current_level = last_level[-1]
        last_level.pop()
    if choice not in current_level:continue
    last_level.append(current_level)
    current_level = current_level[choice]

저자: terry
블로그: http://www.cnblogs. .com/kkterry/
Weibo: http://weibo.com/kkterry
이메일: doubleginger@163.com
재인쇄도 환영하며 출처를 밝혀주세요! 매우 감사합니다!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:파이썬 문자열다음 기사:파이썬 문자열