码迷,mamicode.com
首页 > 编程语言 > 详细

Python编写地区选择-Dict

时间:2017-11-02 11:33:46      阅读:161      评论:0      收藏:0      [点我收藏+]

标签: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

标签:list   dict   地区查询   

原文地址:http://yishi.blog.51cto.com/1059986/1978271

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!