当前位置:   article > 正文

python打开csv文件、计算总成绩_python – 读取CSV文件,计算平均值并打印所述平均值...

python,请编写代码读取“成绩.csv”中的数据,计算每人平均分,把平均分最高的

干得好:

class Student(object):

def __init__(self, name):

self.name = name

self.scores = []

self.highestscore = 0

def __repr__(self):

return '<' + self.name + ', ' \

+ 'high=' + str(self.highestscore) + ', ' \

+ 'avg=' + str(self.getAverage()) + '>'

def addScore(self, score):

self.scores.append(score)

self.highestscore = max(self.highestscore, score)

def getAverage(self):

l = len(self.scores)

if l == 0:

return 0

else:

return sum(self.scores) / l

import csv

results = open("C:\Projetos\Data\Python\Scores1.csv", "r+")

csv1 = csv.reader(results, delimiter=",")

data = {}

highscore = 0

for eachline in csv1:

#print(eachline

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/940747
推荐阅读
相关标签
  

闽ICP备14008679号