1. 程式人生 > >Python編寫地區選擇-Dict

Python編寫地區選擇-Dict

list dict 地區查詢

‘‘‘
Mutselect of the place name.

1.1-3 to Three layer
2."q" to exit.
3."b" to back.
4.other words to retry.
‘‘‘
KyeWords=(‘1‘,‘2‘,‘3‘,‘q‘,‘Q‘)
PlaceName={"遼寧":{"大連":("高新","中山"),"沈陽":("鐵西","渾南"),"葫蘆島":("蓮山","興城")},
      "吉林":{"長春":("大窪","高天"),"四平":("二道河","路陽"),"通遼":("通化","黑道")},
      "黑龍江":{"哈爾":("坪山","故陽"),"大慶":("黑油","千多"),"漠河":("俄國","最北")}}

def Province(PlaceName):        #提取省份到列表
    ProvinceList=[]
    j=1
    for i in PlaceName.keys():
        ProvinceList=ProvinceList+[i]
        print(j,‘.‘,i)
        j+=1
    return (ProvinceList)


def JugdeInput(InputList):
    ProName=""
    PrValue=input("Please select Provide number,press ‘q‘ to exit:")
    if PrValue==‘1‘ :
        ProName=InputList[0]
    elif PrValue==‘2‘:
        ProName=InputList[1]
    elif PrValue==‘3‘:
        ProName=InputList[2]
    elif PrValue==‘q‘ or PrValue==‘Q‘:
        print("tuichu")
        return(‘0‘)
    elif PrValue==‘b‘ or PrValue==‘B‘:
        return(‘-1‘)
    else:
        return

    print("您選擇%s,以下是它的1下屬區域:"%ProName)
    return(ProName)



while True:
    ProvinceLists=Province(PlaceName)
    aaaa=JugdeInput(ProvinceLists)
    if aaaa==‘0‘:
        break
    elif PlaceName.__contains__(aaaa):

        CityName=PlaceName[aaaa]
        while True:
            CityLists=Province(CityName)
            bbbb= JugdeInput(CityLists)
            if bbbb==‘0‘:
                aaaa=‘0‘
                break
            elif CityName.__contains__(bbbb):

                CountryList=CityName[bbbb]
                for name in CountryList:
                    print(name)
                while True:
                    Lastvalue=input("Please press ‘b‘ to return or ‘q‘ to quit:")
                    if Lastvalue==‘q‘ or Lastvalue==‘Q‘:
                        bbbb=‘0‘
                        aaaa=‘0‘
                        break
                    elif Lastvalue==‘b‘ or Lastvalue==‘B‘:
                        break
                    else:
                        continue
            elif bbbb==‘-1‘:
                break

            
            if aaaa==‘0‘:
                break
        if aaaa==‘0‘:
            break
print(‘本次查詢已經結束!‘)

Python的list,dict方法沒有記全,還需要加強.不知道3.0為啥不向下兼容2.0,看書都看混了,大家一定要註意!

本文出自 “回首已是空” 博客,請務必保留此出處http://yishi.blog.51cto.com/1059986/1978271

Python編寫地區選擇-Dict