In this exercise, the optional is_passing() method is supposed to check if the score is passing? How can that be implemented?
Answer
The is_passing() method needs to check the object’s self.score attribute against the class variable Grade.mimimum_passing to determine if the score meets the requirements. If the score is greater than or equal to the minimum passing value, the method should return a value of True. Otherwise, it should return a False.
the score parameter is redundant, and the second line is completely redundant. You already made score available through self in the init method. No need to do it again
You’ll need to use either Grade.minimum_passing or self.minimum_passing. Both will work. (Personally, I prefer Grade.minimum_passing, as it seems more logical to me.)
class Student:
def __init__(self, name, year):
self.name = name
self.year = year
self.grades = []
def add_grade(self, grade):
if type(grade) == Grade: #<--- **here**
self.grades.append(grade)
else:
return
…
I don’t understand this point. Why expression with Grade at this point didn’t raise any Error?
Why word Grade can be called in another class (Student class) have no relationship with it?
Can someone explain it to me?
Thank a lot!
Hi, I’m wondering what Grade(100) actually does.
I wrote the following code:
pieter.add_grade(Grade(100))
print(pieter.grades)
And it prints out:
[<main.Grade object at 0x7f7e59c15ba8>]
Should I write a repre in class Grade?
As I understood, repre just changes how it is shown to the outside, but not change the content itself? So what exactly was stored in pieter.grades after add.grade? Is it just the number 100?
It’s still not clear to me, sorry.
What do I have to type to check if it’s passing ?
pieter.grades.is_passing - not working I I tried many other ways and can’t seem to find a solution.
Please HELP
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
return sum()
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
After writing the is_passing method, how do we use it on one of the students we made to see if they’re passing?
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)
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
roger = Student("Roger van der Weyden", 10)
sandro = Student("Sandro Botticelli", 12)
pieter = Student("Pieter Bruegel the Elder", 8)
pieter.add_grade(Grade(100))
x = Grade(70)
print(x.is_passing())
print(pieter.grades.is_passing())
print(x.is_passing()) works fine.
The line after it doesn’t work, and I’m not sure how to write to check if Pieter is passing. He has a Grade of 100, so shouldn’t there be a way to check that?