猫史档案馆


【Python作品分享】gdp【作品秀】

用户:强乡强乡查看:0 回复:0 评论:0 创建时间:2020-08-21T21:52:47


【作品展示】

center_image

 

【作品介绍】

gdp

 

【作品源代码】

class country:
    def __init__(self,name,gdp):
        self.name=name
        self.gdp=gdp
country_list=[]
def paepare():
    global country_list
    f=open(r'C:\Users\86171\Desktop\suanfa\gdp.txt',encoding='UTF-8')
    lines=f.readlines()
    f.close() 
    for i in range(len(lines)):
        info=lines[i].split('\t')
        country_list.append(country(info[1],int(info[2])))
def search_by_name(name):
    global country_list
    for i in range(len(country_list)):
        if country_list[i].name==name:
            return i
    return -1
def search_by_gdp(gdp):
    global country_list
    for i in range(len(country_list)):
        if country_list[i].gdp==gdp:
            return i
    return -1
paepare()
index=search_by_name('中国')
if index<0:
    print('not found')
else:
    country=country_list[index]
    print(country.gdp*7/12)
    

        

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页