这个东西该怎么办完成这个统计,不怎么会写。有些用谢谢,来帮个忙。
with open("1.text","r") as f:
with open("2.text","w") as F:
n=1
for i in f:
if n!=1:
s=i.strip().split(',')
sum_score=float(s[1])+float(s[2])+float(s[3])+float(s[4])
avg_score=sum_score/4
print(sum_score,avg_score)
F.write(i.strip()+","+str(sum_score)+','+str(avg_score)+"\n")
else:
F.write(i.strip()+","+"总分"+"平均分"+"\n")
n+=1
F.close()
f.close()