Python Object-Oriented Python Instant Objects Method Interactivity

Manny Argueta
Manny Argueta
3,637 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

Pedro Cabral
Pedro Cabral
Front End Web Development Techdegree Student 31,398 Points

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
3,637 Points

Just what I needed. Thanks Pedro!!