Python Object-Oriented Python Instant Objects Method Interactivity

Need Help for this OOPS challenge for Feedback

Here is my Code Snippet

first_class.py
class Student:
    name = "Amar"
    grade = 49

    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

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 24,835 Points

You're close. The issue is you added a property variable which is confounding the grader. In addition, you are testing a property rather than the variable passed in. See below:

class Student:
    name = "Your Name"
    # grade = 49 # the grader did not like this extra property (I commented out)

    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):
        # fix the conditional here to what is below, testing self.grade won't quite work
        if grade > 50:
            return self.praise()
        else:
            return self.reassurance()

Good luck with your Python journey!

Thanks Jeff. Appreciate your help!!.