python learning day06 practice --- three directory optimization

"" " 
Needs 
three directory 
① demonstrate provincial directory 
② provinces selected by the user 
    1. corresponding level city out of 
    2. You can return to the previous menu 
    3. You can select level city 
    4. You can exit the program 
③ Select the prefecture-level city 
    1. out of the corresponding county 
    2. You can return to the previous menu 
    3. You can exit 

"" " 
chinese_city = {
     ' Jiangsu Province ' : {
         ' Suzhou ' : [ ' Suzhou area ' , ' high-tech zones ' , ' industrial park ' ],
         ' Zhenjiang ' : [ ' Runzhou ' , 'Jingkou District ', ' Danyang ' ],
         ' Nanjing ' : [ ' Drum region ' , ' Yuhuatai ' , ' Jianye ' ] 
    }, 
    ' Zhejiang ' : {
         ' Sue City ' : [ ' Kou area ' , ' high zone ' , ' work area ' ],
         ' towns ' : [ ' Run area ' , ' Beijing area ', ' Dan City' ],
         ' Nan ' : [ ' drum area ' , ' rain ' , ' construction zone ' ] 
    }, 
    ' Guangdong Province ' : {
         ' City ' : [ ' Soviet ' , ' New ' , ' park ' ] ,
         ' River City ' : [ ' state area ' , ' port area ' , ' Yang City '],
        '京市': ['楼区', '台区', '邺区']
    }

}

current_level = chinese_city
parents_level = []

while True:
    for key in current_level:
        print(key)
    choice = input("请输入")
    if choice in current_level:
        parents_level.append(current_level)
        current_level = current_level[choice]
    elif choice == 'quit':
        break
    elif choice == 'return':
        if parents_level:
            current_level = parents_level.pop()
    else:
        print("输入错误")

 

Guess you like

Origin www.cnblogs.com/igeniuswwh/p/11260667.html