1. 程式人生 > >python多級選單(簡單邏輯)

python多級選單(簡單邏輯)

# encoding: utf-8
data= {
    '北京':{
        "昌平":{
            "沙河":["oldboy","test"],
            "天通苑":["鏈家地產","我愛我家"]
        },
        "朝陽":{
            "望京":["賓士","陌陌"],
            "國貿":{"CICC","HP"},
            "東直門":{"Advent","飛信"},
        },
        "海淀":{},
    },
    '山東':{
        "德州":{},
        "青島":{},
        "濟南":{}
    },
    '廣東':{
        "東莞":{},
        "常熟":{},
        "佛山":{},
    },
}
while True:
    for i in data:
        print(i)
    choose1=input('請輸入你的選擇1,q[退出]:')
    if choose1 in data:
        while True:
            for n in data[choose1]:
                print(n)
            choose2=input('請輸入你的選擇2,q[退出],b[返回]:')
            if choose2 in data[choose1]:
                while True:
                    for j in data[choose1][choose2]:
                        print(j)
                    choose3 = input('請輸入你的選擇3,q[退出],b[返回]:')
                    if choose3 in data[choose1][choose2]:
                        while True:
                            for s in data[choose1][choose2][choose3]:
                                print(s)
                            choose4=input('請輸入你的選擇4,q[退出],b[返回]')
                            if choose4 == 'q':
                                exit()
                            elif choose4=='b':
                                break
                    elif choose3 == 'q':
                        exit()
                    elif choose3 == 'b':
                        break
            elif choose2 == 'q':
                exit()
            elif choose2 == 'b':
                break
    elif choose1 == 'q':
        exit()