PYTHON3 列表和字典的应用

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Virgin Forest
data ={
    "广东":{
        "深圳":{
            "宝安区":{"石岩","福永","西乡"},
            "南山区":{"南头","蛇口","竹子洲"},
            "龙华新区":{"观澜","大浪","观湖"}
        },
        "广州":{
            "天河区":{"沙东","林和","棠下"},
            "花都区":{"狮岭","赤坭","炭步"},
            "白云区":{"陈洞","华坑","安平"}
        }
    },
    "湖南":{
        "长沙":{
            "开福区":{"福城","丽臣","花城"},
            "天心区":{"天剑","木莲","文源"},
            "雨花区":{"泰安","金福","三湘"}
        },
        "衡阳":{
            "常宁县":{"宜潭","兰江","弥泉"},
            "衡南县":{"洪山","三塘","谭子山"},
            "祁东县":{"归阳","过水坪","双桥"}
        }
    }
}


exit_flage = False
print("输入'B'返回上一层,输入'Q'退出程序")
while not exit_flage:
    for i in data:
        print(i)
    choice = input("选择进入第一层:")
    if choice in data:
        while not exit_flage:
            for i1 in data[choice]:
                print(i1)
            choice1 = input("选择进入第二层:")
            if choice1 in data[choice]:
                while not exit_flage:
                    for i2 in data[choice][choice1]:
                        print(i2)
                    choice2 = input("选择进入第三层:")
                    if choice2 in data[choice][choice1]:
                        while not exit_flage:
                            for i3 in data[choice][choice1][choice2]:
                                print(i3)
                            choice3 = input("这是最后一层了!")
                            if choice3 == 'q' or choice3 == 'Q':
                                exit_flage = True
                            if choice3 == 'b' or choice3 == 'B':
                                break
                    if choice2 == 'q' or choice2 == 'Q':
                        exit_flage = True
                    if choice2 == 'b' or choice2 == 'B':
                        break
            if choice1 == 'q' or choice1 == 'Q':
                exit_flage = True
            if choice1 == 'b' or choice1 == 'B':
                break

    if choice == 'q' or choice == 'Q':
        exit_flage = True

 

posted @ 2017-09-01 11:28  virgin-forest  阅读(207)  评论(0)    收藏  举报