3rd level menu work

# Author :yanpengtao

data = {
    "Beijing": {
        "Changping": {
            "沙河": ["oldboy", "test"],
            "Tiantongyuan": ["Lianjia Real Estate", "I love my home"],
        },
        "Chaoyang": {
            "Wangjing": ["Benz", "Momo"],
            "国贸": ["CICC", "HP"],
            "Dongzhimen": ["Advent", "Fetion"]
        },
        "Haidian": {
            "": [],
            "": [],
            "": [],
        },
    },
    "Shandong": {},
    "Guangdong": {},
}
exit_flag = False
while not exit_flag:
    for i in data:
        print(i) # print the first layer
    choice = input("Choose to enter 1>>>")
    if choice in data :
        while not exit_flag:
            for i2 in data[choice]:
                print("\t", i2)
            choice2 = input("Choose to enter 2>>>")
            if choice2 in data[choice]:
                while not exit_flag:
                    for i3 in data[choice][choice2]:
                        print("\t", i3)
                    choice3 = input("Choose to enter 3>>>")
                    if choice3 in data[choice][choice2]:
                        for i4 in data[choice][choice2][choice3]:
                            print(i4)
                        choice4 = input("Enter b to return to the previous level >>>")
                        if choice4 == "b":
                            pass
                        elif choice4 =="q":
                            exit_flag = True
                    if choice3 == "b":
                        break
                    elif choice3 == "q":
                        exit_flag = True
            if choice2 == "b":
                break
            elif choice2 == "q":
                exit_flag = True
    if choice == "b":
        print("Already the top level!")
        break

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325058857&siteId=291194637