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

Pavlo Vasylyshyn
Pavlo Vasylyshyn
4,641 Points

How come my solution does not pass validation?

It works in my workspace. https://teamtreehouse.com/workspaces/29745632# test_1.py

Thanks, Pavlo

first_class.py
class Student:
    name = "Pavlo"

    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):
        self.grade = grade
        if self.grade > 50:
            return me.praise()
        return me.reassurance()

me = Student()
print(me.feedback(55))

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You are very close! In the feedback method, the current instance is referred to as self not "me". Replace "me" with self and it will pass the challenge!!

Pavlo Vasylyshyn
Pavlo Vasylyshyn
4,641 Points

Corrected to "self" and it worked. Odd though, in Workspaces both "me" and "self" within "feedback" method reference to a same memory location. Maybe it's Python version related as well.

============================

def feedback(self, grade):
    print(me)
    print(self)
    self.grade = grade
    if self.grade > 50:
        return me.praise()
    return me.reassurance()

============================

Thank you Chris!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

You are correct that me exists because you have created it outside of the function with a specific value. So, feedback will provide the correct answer as long as feedback is only called on the me instance of Student.

The challenge checker will create its own independent instances during testing that do will not pass because of they will be different from me.

slacker = Student()
print(slacker.feedback(17))
# fails with praise for 'me' instead of slacker