我是靠谱客的博主 炙热眼神,这篇文章主要介绍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

最后

以上就是炙热眼神最近收集整理的关于python求平均工资_在Python3中计算列表的平均值的全部内容,更多相关python求平均工资_在Python3中计算列表内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(131)

评论列表共有 0 条评论

立即
投稿
返回
顶部