python求平均工资_在Python3中计算列表的平均值

我目前正在尝试计算由类中的方法创建的列表的平均值。首先将所有信息传递给一个类,该类记录/返回从main函数传递的数据。问题是我要从main函数传入什么来首先检索self.\u marks列表,然后操作它以返回平均值。另外,我是否为calculatevaragemark部分使用了正确的代码?提前谢谢

代码如下:class Student :

def __init__(self, id):

self._studentId = id

self._marks = []

##

# Converts the student to a string .

# @return The string representation .

#

# Sets the student's ID.

# @param newId is the student's new ID.

#

def setStudentId(self, id):

self._studentId = id

##

# Gets the student's ID.

# @return the student's ID

#

def getStudentId(self, newId):

return self._newId

##

# appends a mark to the marks list

#

def addMark(self, mark):

self._marks.append(mark)

def __repr__(self) :

# Build a string starting with the student ID

# followed by the details of each mark .

s = "Student ID :" + self._studentId + " "

if len(self._marks) == 0 :

s += " "

else :

for mark in self._marks :

s += " Course Module: " + mark.getModule() + " Raw Mark: " + str(mark.getRawMark())

return s

##

# Method to calculate the students average mark

#

def calculateAverageMark(self):

totalMarks = 0

count = 0

for mark in self._marks :

if mark == 0 :

count = count

else :

count = count + 1

totalMarks = totalMarks + mark

average = totalMarks / count

return average

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值