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

Emil Hejlesen
Emil Hejlesen
3,014 Points

Why doesn't this work?

i just don't get i cause i can't find the error in this code

first_class.py
class Student:
    name = "Your Name"
    grade = 50

    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 self.grade > 50:
            self.praise()
        else:
            self.reassurance()

1 Answer

andren
andren
28,558 Points

There are two issues:

  1. You are not supposed to add grade as a class attribute, only as a parameter. That means that you should not define it at the top of the class, and not refer to it with the self keyword.
  2. You are asked to return the result of either the praise or reassurance methods. You call those methods but you do not return their result.

If you fix those two issues like this:

class Student:
    name = "Your Name"
    # praise should not be defined as a class attribute

    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: # Since grade is a parameter you don't use the self keyword
            return self.praise() # Return the result of the method
        else:
            return self.reassurance() # Return the result of the method

Then your code will pass.

Emil Hejlesen
Emil Hejlesen
3,014 Points

hey thx for the help i have tried this and it didn't work it said there was no grade in the class but thx for the help