Can’t make get_average to work

I am completely lost.
I can’t make get_average to work. Tried everything that my beginner brain could think of or fin on blogs. Could someone explain, please, what am I doing wrong? Please :slight_smile:

class Student:
    def __init__(self, name, year):
        self.name = name
        self.year = year
        self.grades = []

    def add_grade(self, grade):
        if type(grade) == Grade:
            self.grades.append(grade.score)

    def get_average(self):
        avg = 0
        for i in self.grades:
           avg += i
        return avg/len(self.grades)

class Grade:
    minimum_passing = 65

    def __init__(self, score):
        self.score = score

    def is_passing(self):
        if self.score >= Grade.minimum_passing:
            return True
        else:
            return False


# execute
roger = Student("Roger van der Weyden", 10)
sandro = Student("Sandro Botticelli", 12)
pieter = Student("Pieter Bruegel the Elder", 8)
x = Grade(60)
pieter.add_grade(x)
pieter.add_grade(Grade(77))

print(pieter.get_average)
pieter.grades.is_passing

1 Like

A Grade object has a 'score' attribute. See the add_grade method for a hint.

Ok, i get that.
Thats why in add_grade i did self.grades.append(grades.score) thus I’d have the number directly stored in self.grades.
But that apparently doesn’t work. I tried :
For i in self.grades.score
Or
For i in self.grades:
Avg += i.score that only gives an error no .score for list.
Thus I’m lost… What am I missing ?

1 Like

What if instead of appending the score, we append the actual Grade object?

1 Like