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 trialJulian Silvestri
4,214 PointsMethod Interactivity Stuck on challenge
I am trying to figure out this challenge. But I keep getting an error Exception: reassurance is not defined...
any thoughts?
here is my code
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(self,grade):
if grade < 50:
return(praise())
if grade > 50:
return reassurance
4 Answers
Steven Parker
231,269 PointsYou forgot to prefix the method names with "self.".
When calling methods inside your own class, be sure to put "self." in front of the method names.
Also, the instructions say "return the reassurance method's result", but on the last line you return the method itself. To return the method's result, you would call it by placing parentheses after the name like you did for "praise".
Finally, check your conditionals. You might need to make some changes to make sure the right thing happens for the right argument values.
James Balliet
Courses Plus Student 1,273 PointsI have no clue what your talking about. I tried the following code, which is correct, and I get the error code... Bummer! Exception: name 'praise' is not defined
class Student: name = "James"
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(self,grade):
if grade > 50:
return praise(self)
if grade < 50:
return reassurance(self)
Please advise
Steven Parker
231,269 PointsThe "self." goes in front of the method name, for example:
return self.praise()
James Balliet
Courses Plus Student 1,273 Pointsok. I guess I am missing some critical understanding of the code. Anything you can do to help me to comprehend what I don't understand?
James Balliet
Courses Plus Student 1,273 Points@Steven Parker - why?
Steven Parker
231,269 PointsIf you mean "why do you add 'self'?", it identifies that a class method is being called instead of a global function of that name. This is similar to the other methods referring to "self.name
" instead of just "name
".
If that's not what you were asking, perhaps you could be a bit more specific.
Julian Silvestri
4,214 PointsJulian Silvestri
4,214 Pointswhoops I already see syntax errors