python 国家/中国/省份/市区/县城 四级菜单查询

1.四级菜单
2.可依次选择进入各省份子菜单
3.每一级菜单可退回上一级菜单

4.每一级菜单都可以退出菜单

tmp = country

def worldMenue():
    for key in country:
        print key

def countryMenu(country):
    global  tmp
    country_count = 0
            
    while True:
        c = raw_input("enter a option to view this area\r\nenter q exit !\r\nenter r return to the previous menu: ")
        if c == 'q':
            sys.exit()
        if c == 'r':
            for key in tmp:
                print key
            return tmp
        else:
            for key in country:
                if c == key:
                    for key in country[c]:
                        print key
                    tmp = country
                    country = country[c]
                    if(isinstance(country,list)):
                        sys.exit()
                else:
                    country_count +=1
            if country_count == len(country):
                country_count = 0
                print 'No exist this area option! please enter again'
            else:
                break
    return country



worldMenue()
while True:
    country = countryMenu(country)
code 中所用到的国家、省、市区、县城 名称在字典和列表中太大,请点击 国省市县字典列表 在该链接下载!

你可能感兴趣的:(python应用及代码)