赞
踩
score.csv文件中存储的是一个学生在第一季度同一学科对应的月考成绩,求出每一门学科在三个月中的平均成绩,将结果输出在考生文件夹。
fi = open("score.csv","r") fo = open("avg-score.txt","w") ls = [] x = [] sum = 0 for row in fi: ls.append(row.strip('\n').split(',')) for line in ls[1:]: for i in line[1:]: sum = int(i)+sum avg = sum/3 x.append(avg) sum = 0 fo.write("语文:{:.2f}\n数学:{:.2f}\n英语:{:.2f}\n物理:{:.2f}\n科学:{:.2f}".format(x[0],x[1],x[2],x[3],x[4])) fi.close() fo.close()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。