Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames Nobles
8,884 PointsException: unorderable types: Student() > int()
Not sure what the issue is here. Is it complaining because grade is a string and 50 is an int?
class Student:
name = "Your Name"
def praise(self):
return "You inspire me, {}".format(self.name)
def reassurance(self):
return "Chin up, {}. You'll get it next time!".format(self.name)
def feedback(grade, self):
if grade > 50:
return self.praise()
else:
return self.reassurance()
2 Answers
AJ Salmon
5,675 PointsHi James! In your method, the first argument to the method needs to be itself. By convention, self is used to represent that, but it's not required, and python doesn't search for the keyword 'self'. In this case, it's treating 'grade' as your 'self' argument, and the error means that the Student class doesn't support that operation. In other words, it thinks that 'grade' is an instance of the class, not an integer. Switch the order of grade and self around in the parameter of the feedback method and it passes with flying colors :)
Andrew McLane
3,385 Pointsthanks for the reply!
James Nobles
8,884 PointsJames Nobles
8,884 PointsThanks. That worked.
Andrew McLane
3,385 PointsAndrew McLane
3,385 PointsI thought self represented an instance, not the method itself. Also, if we don't have to use the literal word self as the argument, why does it treat grade as an instance of the class? Not sure about this explanation I guess.
AJ Salmon
5,675 PointsAJ Salmon
5,675 PointsAndrew, that's correct, and although when I say 'itself' I mean an instance of the class, I should have been more clear that you're not passing the actual method to itself as an argument. The answer to your second question is related to the same miscommunication; the first argument to a method will be treated as the instance, so in the above example,
grade
will be what the method uses as the placeholder for the instance of the class. Hopefully, this clears it up a bit, I apologize for my initial answer being admittedly confusing, haha. If you need any further clarification I'd be happy to elaborate on it, to the best of my ability!! :)