so i’m doing one of the optional bits, and this is what i’ve got for one of them. it’s to tell if something is a passing or failing grade, and return which it is. however, the error i get is weird, it tells me that the “>” operator cannot be done between 2 ints. considering i’ve done “>” between several different things that fit into the “int” type, i’m assuming this is not the actual error. what has gone wrong?
class Grade:
minimum_passing = 65
def __init__(self, score):
self.score = score
def is_passing(self, minimum_passing):
self.is_passing = minimum_passing
def __repr__(self):
if self.score > self.is_passing:
return "pass"
else:
return "fail"
Is the variable self.is_passing always an int in your code? How about self.score?
Python can be tricky here without any strong typing. The way I see it self.passing
isn’t instantiated in the class until the function is_passing
is invoked.
If you want to debug you can use the python debugger, pdb.
I think there’s newer ways now but I’m still using python 3.6 daily so i would do
class Grade:
minimum_passing = 65
def __init__(self, score):
self.score = score
def is_passing(self, minimum_passing):
self.is_passing = minimum_passing
def __repr__(self):
import pdb; pdb.set_trace()
if self.score > self.is_passing:
return "pass"
else:
return "fail"
This halts your program where the trace is set and you can query the state of your variables like:
>> type(self.score)
>> type(self.is_passing)
3 Likes