有人知道这个Python公式有哪些问题吗??关于找到GDP的min,max还有用find方程。
我在做一个Pyton的作业,题目要求是找GDP的min,max还有用Find公式。有人帮我看一下这个代码是否有错,有错的话错在哪里了?deffind_gdp(line,i...
我在做一个Pyton的作业,题目要求是找GDP的min, max 还有用Find 公式。有人帮我看一下这个代码是否有错,有错的话错在哪里了?
def find_gdp(line,index):
line = line[76:]
value_index = 0
while line:
line, value = line[12:],line[:12]
#print(value_index,index)
if value_index == index:
return value
value_index += 1
def open_file():
while True:
file_name = input('Enter a file name: ')#GDP.txt
try:
fp = open(file_name, 'r')
return fp
except:
print('Error. Please try again')
def find_min_percent(line):
line = line[76:]
min_value=10000000
value_index = 0
while line:
line, value = line[12:],line[:12]
value = float(value)
if value<min_value:
min_value = value
min_value_index = value_index
value_index += 1
return min_value, min_value_index
def find_max_percent(line):
line = line[76:]
max_value=-10000000
value_index = 0
while line:
line, value = line[12:],line[:12]
value = float(value)
if value>max_value:
max_value = value
max_value_index = value_index
value_index += 1
return max_value, max_value_index
def find_gdp(line,index):
line = line[76:]
value_index = 0
while line:
line, value = line[12:],line[:12]
#print(value_index,index)
if value_index == index:
return value
value_index += 1
def display(min_val, min_year, min_val_gdp, max_val, max_year, max_val_gdp):
print('\nGross Domestic Product')
#print('min',min_val, min_year, min_val_gdp)
print("{:<10s}{:>8s}{:>6s}{:>18s}".format('min/max','change', 'year', 'GDP (trillions)'))
print("{:<10s}{:>8.1f}{:>6d}{:>18.2f}".format('min',min_val, min_year, min_val_gdp))
print("{:<10s}{:>8.1f}{:>6d}{:>18.2f}".format('max',max_val, max_year, max_val_gdp))
def main():
fp = open_file()
for v,i in enumerate(fp):
if v == 7:
year_line = i
elif v == 8:
gdp_line1 = i
elif v == 43:
gdp_line2 = i
break
#print(year_line)
min_val = find_min_percent(gdp_line1)
#print(min_val)
max_val = find_max_percent(gdp_line1)
#print(max_val)
min_year = int(find_gdp(year_line, min_val[1]))
#print(min_year)
min_val_gdp = float(find_gdp(gdp_line2, min_val[1]))/1000
#print(min_val_gdp)
max_year = int(find_gdp(year_line, max_val[1]))
#print(max_year)
max_val_gdp = float(find_gdp(gdp_line2, max_val[1]))/1000
#print(max_val_gdp)
display(min_val[0], min_year, min_val_gdp, max_val[0], max_year, max_val_gdp)
fp.close() 展开
def find_gdp(line,index):
line = line[76:]
value_index = 0
while line:
line, value = line[12:],line[:12]
#print(value_index,index)
if value_index == index:
return value
value_index += 1
def open_file():
while True:
file_name = input('Enter a file name: ')#GDP.txt
try:
fp = open(file_name, 'r')
return fp
except:
print('Error. Please try again')
def find_min_percent(line):
line = line[76:]
min_value=10000000
value_index = 0
while line:
line, value = line[12:],line[:12]
value = float(value)
if value<min_value:
min_value = value
min_value_index = value_index
value_index += 1
return min_value, min_value_index
def find_max_percent(line):
line = line[76:]
max_value=-10000000
value_index = 0
while line:
line, value = line[12:],line[:12]
value = float(value)
if value>max_value:
max_value = value
max_value_index = value_index
value_index += 1
return max_value, max_value_index
def find_gdp(line,index):
line = line[76:]
value_index = 0
while line:
line, value = line[12:],line[:12]
#print(value_index,index)
if value_index == index:
return value
value_index += 1
def display(min_val, min_year, min_val_gdp, max_val, max_year, max_val_gdp):
print('\nGross Domestic Product')
#print('min',min_val, min_year, min_val_gdp)
print("{:<10s}{:>8s}{:>6s}{:>18s}".format('min/max','change', 'year', 'GDP (trillions)'))
print("{:<10s}{:>8.1f}{:>6d}{:>18.2f}".format('min',min_val, min_year, min_val_gdp))
print("{:<10s}{:>8.1f}{:>6d}{:>18.2f}".format('max',max_val, max_year, max_val_gdp))
def main():
fp = open_file()
for v,i in enumerate(fp):
if v == 7:
year_line = i
elif v == 8:
gdp_line1 = i
elif v == 43:
gdp_line2 = i
break
#print(year_line)
min_val = find_min_percent(gdp_line1)
#print(min_val)
max_val = find_max_percent(gdp_line1)
#print(max_val)
min_year = int(find_gdp(year_line, min_val[1]))
#print(min_year)
min_val_gdp = float(find_gdp(gdp_line2, min_val[1]))/1000
#print(min_val_gdp)
max_year = int(find_gdp(year_line, max_val[1]))
#print(max_year)
max_val_gdp = float(find_gdp(gdp_line2, max_val[1]))/1000
#print(max_val_gdp)
display(min_val[0], min_year, min_val_gdp, max_val[0], max_year, max_val_gdp)
fp.close() 展开
2个回答
展开全部
你是打印?还是图像处理?
打印啦打印.
1 简单的:在PS里 打印设置选择适合比例打印就可以;2 把图插入到word里,把图缩小到页面中间,打印也可以;还有很多方法,不知道你是具体什么情况
不是这样,我写了个打印的程序,在程序中打印,需要对纸张尺寸和图片尺寸进行计算,算出居中结果后给出相应的值才能居中.
什么语言,编写的什么程序,你是卡在不会计算居中位置?还是什么其他问题?
用的python,想做a4的居中显示,和居中打印.后来夭折了,这帖子是去年8月发来求助计算公式的
晕,刚才随机看到的,没看时间,就回答了!
哈哈,谢谢你的热心回答.就采纳你啦.
打印啦打印.
1 简单的:在PS里 打印设置选择适合比例打印就可以;2 把图插入到word里,把图缩小到页面中间,打印也可以;还有很多方法,不知道你是具体什么情况
不是这样,我写了个打印的程序,在程序中打印,需要对纸张尺寸和图片尺寸进行计算,算出居中结果后给出相应的值才能居中.
什么语言,编写的什么程序,你是卡在不会计算居中位置?还是什么其他问题?
用的python,想做a4的居中显示,和居中打印.后来夭折了,这帖子是去年8月发来求助计算公式的
晕,刚才随机看到的,没看时间,就回答了!
哈哈,谢谢你的热心回答.就采纳你啦.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询