Python Object-Oriented Python Instant Objects Method Interactivity

Misha Morse
Misha Morse
3,711 Points

Stuck!!! Please help :/

Just not sure what I'm doing wrong here. Very stuck

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

    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 (>= 51):
            return self.praise
        else:
            return self.reassurance

2 Answers

Steven Parker
Steven Parker
201,323 Points

You have the right idea, but a few syntax issues:

  • an argument (like "grade") does not need a "self." prefix
  • there should not be parentheses around part of the comparison
  • when calling a method, you must put parentheses after the method name
    def feedback(self, grade):
        if grade >= 51:
            return self.praise()
        else:
            return self.reassurance()
Misha Morse
Misha Morse
3,711 Points

Thankyou Steven! I figured out that I had left out the () after calling the method and removed the () from the comparison but was still stuck due to the self. preceding grade. You’re a lifesaver.

Amar P
Amar P
1,983 Points

Hey Steve,

Im just continuing on this thread

Here is my Code Snippet

class Student:
    name = "Amar"
    #grade = 43

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

new = Student()
print(new.feedback(49))
print(new.feedback(51))

I tried playing around with above & Im currently stuck

1) When i run above code in my workspace, it gives message 'AttributeError: 'Student' object has no attribute 'grade' In the challenge they asked following method feedback. It should take an argument named grade. My feedback method does that then why i'm i getting AttributeError?

2) I uncommented grade & ran the code again. In my workspace it always runs reassurance method & ignores the function calls with grades 49 & 51. In the compiler where i check my work, it gives message Bummer: Didn't find the the praise message with a grade over 50.

Following is the challenge i see

  • Alright, I need you make a new method named feedback. - Done
  • It should take an argument named grade. Methods take arguments just like functions do. You'll still need self in there, though. - Done

  • If grade is above 50, return the result of the praise method. - Done

  • If it's 50 or below, return the reassurance method's result. - Done

Steven Parker
Steven Parker
201,323 Points

Note that "continuing on this thread" would only apply to comments about the original poster's question. Always start a new, fresh question instead of posting one as an "answer".

But in this case, the issue is the same as what I covered in my first hint to Misha.