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 trial

Python Object-Oriented Python Instant Objects Method Interactivity

Julian Silvestri
Julian Silvestri
4,214 Points

Method 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

first_class.py
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
Julian Silvestri
Julian Silvestri
4,214 Points

whoops I already see syntax errors

4 Answers

Steven Parker
Steven Parker
231,261 Points

You 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
PLUS
James Balliet
Courses Plus Student 1,273 Points

I 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
Steven Parker
231,261 Points

The "self." goes in front of the method name, for example:

        return self.praise()
James Balliet
PLUS
James Balliet
Courses Plus Student 1,273 Points

ok. 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?

Steven Parker
Steven Parker
231,261 Points

If 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.