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

Manny Argueta
Manny Argueta
5,443 Points

Multiple methods in a class

I'm not sure I'm understanding this question.

To pass an argument to a function, you would include in at feedback(grade) where grade is the argument and self is the parameter right?

When I run this or slight variations, the error is either "grade is not an attribute" or "Couldn't find student" or "praise/reassurance is not an attribute"

How do you return either method using this feedback method?

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

    def feedback(self):
        if self.grade >= 51:
            return praise
        else:
            return reassurance
    feedback(grade)

    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)

1 Answer

Hi,

Regarding the difference between argument and parameter:

def method_name(self, this_is_called_a_parameter):
  # code

method_name(this_is_called_an_argument)

A few things to note:

  1. You are being asked to create a method named feedback, which you did but you forgot that it should receive a "grade" as well;
  2. Inside the if condition, you should access the argument that was passed in, grade, using the variable by itself without using self.grade. You would use self, if you were accessing an attribute of the class, but in this case you are accessing a piece of data that was passed into the function when it was called;
  3. On your returns, you should use the keyword self as in self.praise() and self.reassurance() because in this case you are accessing the instance's methods, so you will need self. Also, don't forget about the parenthesis for the method call;
  4. Regarding the message Can't find student, that's because you are calling feedback(grade) and that's not necessary;
Manny Argueta
Manny Argueta
5,443 Points

Just what I needed. Thanks Pedro!!