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

Didn't find the the praise message with a grade under 50.

I am using the random function why is it giving me this error? thank!!

first_class.py
import random

class Student:
    name = "Juan"
    grade = random.randint(50,51)

    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, *args):
        if self.grade > 50:
            return self.praise()
        else:
            return self.reassurance()

3 Answers

Hi there,

You code looks fine? Only problem I can see is that your random number can only be 50 or 51?

Hi Juan,

You don't need to make grade a part of the class - and nor do you set its value; that's provided by the code challenge tests. You can remove the reference to grade at the top of the class. The grade is passed into the feedback method by the caller of that method.

Inside the method, use that grade parameter to do the tests, like you have done. But in the method signature, remove *args and pass in grade instead; make sure self remains there, though. Then, compare grade (no self keyword as it isn't part of the class, it is just a local variable) to 50, calling the two methods, as you have done.

My code ended up looking like this; I am sure there are other solutions too:

class Student:
    name = "Your Name"

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

I hope that makes sense.

Steve.

great thanks guys!!

No problem! :+1: :smile: