Dictionary - four menu

Function:

1, the parent menu enter a submenu, so

2, to return to the previous menu

= privince_info {
     " Henan " : {
         " Xinyang City " : {
             " Shangcheng County " : [ " double-Chun Town " , " River Phoenix Town " , " Sanliping " ],
             " Huangchuan County " : [ " White shop Township " , " Ptah town " ]
        },
        " Zhumadian " : {
             " Queshan " : [ " Li Zhen " , " Liu Zhen " ],
             " Biyang " : [ " two Pu Cun " , " pay Township " ]
        }
    },
    " Hubei " : {
         " Wuhan " : {
             " riverbank " : [ " Huanggang " , " Xiaogan " ],
             " Wuchang District " : [ " Cui Liu village " , " pear village " ]
        }
    }
}
Print ( " return to enter a 'b'; Enter 'q' quit the program " )


while True:
    for print_privince in privince_info:
        print(print_privince)
    choice_privince = INPUT ( " Please select a province: " )
     IF choice_privince == ' b '  or choice_privince == ' B ' :   # input b of a return 
        BREAK 
    elif choice_privince == ' Q '  or choice_privince == ' Q ' :   # enter q to quit the program 
        quit ()
     IF choice_privince not  in privince_info:   # province if the input is no longer dictionary, re-enter 
        the Continue 
    # for privince in privince_info[choice_privince]:
    #     print(">> " + privince)
    while True:
        for privince in privince_info[choice_privince]:
            print(">> " + privince)
        choice_city = INPUT ( " Select City: " )
         IF choice_city == ' b '  or choice_city == ' B ' :   # input b of a return 
            BREAK 
        elif choice_city == ' Q '  or choice_city == ' Q ' :
            quit()
        IF choice_city not  in privince_info [choice_privince]:   # If you enter a city no longer dictionary, reenter 
            continue

        while True:
            for city in privince_info[choice_privince][choice_city]:
                print(">>>> " + city)
            choice_town = INPUT ( " Please select Town: " )
             IF choice_town == ' b '  or choice_town == ' B ' :   # input b of a return 
                BREAK 
            elif choice_town == ' Q '  or choice_town == ' Q ' :
                quit()
            IF choice_town not  in privince_info [choice_privince] [choice_city]: # If you enter the town no longer dictionary, reenter 
                continue

            while True:
                for town in privince_info[choice_privince][choice_city][choice_town]:
                    print(">>>>>> " + town)
                choice_cun = INPUT ( " Input 'b' returns; input 'q' quit: " )
                 IF choice_cun == ' B '  or choice_cun == ' B ' :
                     BREAK 
                elif choice_cun == ' Q '  or choice_cun == ' Q ' :
                    quit()
                IF choice_cun in privince_info [choice_privince] [choice_city] [choice_town]: # Enter the last one does not execute anything, to prevent an error 
                    pass

 

Guess you like

Origin www.cnblogs.com/leejay/p/12003284.html