Can you help me to solve the problem, why am I not able to call my functions? I try to calculate the average mark of all student objects created but it somehow doesnt work.
class Student:
anz = 0
def __init__(self, vorname, nachname, studetnId, averageMark):
self.vorname = vorname
self.nachname = nachname
self.studentId = studetnId
self.averageMark = averageMark
Student.anz += 1
def totalAverageMark(self, input):
summe = 0
for s in input:
summe += self.averageMark
return (summe / Student.anz)
def getName(self, arr):
for s in arr:
return self.nachname
students = [Student("Maxine", "Muster", 2, 1.0), Student("Bert", "Beispiel", 1, 2.0)]
print(students.getName())
print(students.totalAverageMark())
It says: AttributeError: 'list' object has no attribute 'totalAverageMark'
students) in Python?studentsis a list. As the error tells you,listobjects do not have those methodsStudentfor their name (getName()), but asking one about the total average mark (totalAverageMark()) you can't expect them to return any info that includes other students. BTW: What is the meaning of the parameter togetName()? It doesn't make sense. You'd see that yourself if you made a human language description of what each method does, including the paramers.inputas a parameter name indef totalAverageMark(self, input):.