Python 使用序列解析式计算 CSV 文件的平均成绩
with open('math.csv') as file:
score = file.readlines() # 一次性读取整个文件,自动将文件内容分析成一个行的'字符串'列表。
list1 = [int(i.strip()) for i in score] # 使用序列解析式,计算班级平均成绩
print('班级平均成绩为:',sum(list1)/len(list1))
原文地址: https://www.cveoy.top/t/topic/ocvq 著作权归作者所有。请勿转载和采集!