Python3小白初体验

三层循环嵌套,以后优化

data = {
    "北京":{
            "a":{
                "小白":"1",
                "小红":"2"
                },
            "b":{
                "小黑":"3",
                "小其":"4"
                }
            },
    "广东":{
            "c":{
                "小明":"5",
                "小新":"6"
                },
            "d":{
                "小孩":"7",
                "小小":"8"
                }
        },
    "广西":{
            "e":{
                "小蝶":"9",
                "小费":"10"
                },
            "f":{
                "小高":"11",
                "小p":"12"
                }
        },
    }
tt_flag = False
#三层循环
print(data["广西"]["e"]["小蝶"])
while not tt_flag:
    for i in data:
        print(i)
    chioce = input("请选择进入:")
    if chioce in data:
        while not tt_flag:
            for j in data[chioce]:
                print(j)
            chioce2 = input("请选择进入:")
            if chioce2 in data[chioce]:
                while not tt_flag:
                    for k in data[chioce][chioce2]:
                        print(k)

                    chioce3 = input("请输入进入:")
                    if chioce3 in data[chioce][chioce2]:
                        while not tt_flag:
                            for l in data[chioce][chioce2][chioce3]:
                                print(l)
                            choice4 = input("最后一层,按c返回:按q退出")
                            if choice4 == "c":
                                break
                            elif choice4 == "q":
                                tt_flag = True
                                
                    if chioce3 == "c":
                        break
                    elif chioce3 == "q":
                        tt_flag = True
                        
            if chioce2 == "c":
                break
            elif chioce2 == "q":
                tt_flag = True
    if chioce == "c":
        break
原文地址:https://www.cnblogs.com/Liang-jc/p/8613821.html