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

Challenge help

Hi! I'm really struggling with this challenge. I can't seem to get anything but the self.reassurance() method called every time I run the code. How do I get theself.praise() method to run in my conditional statement. Please help!

first_class.py
class Student:
    name = "Golo"
    def __init__(self, name="golo", grade, **kwargs):
        self.name = name
        self.grade = grade

        for key, value in kwargs.items():
            setattr(self, key, value)

    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()

2 Answers

Andy Hughes
Andy Hughes
8,479 Points

Hi Quy Vo,

You're not far off but it seems you've added a level of complexity not needed to pass the challenge. This part:

def __init__(self, name="golo", grade, **kwargs):
        self.name = name
        self.grade = grade

        for key, value in kwargs.items():
            setattr(self, key, value)

is not necessary. The rest of your code will work if you change the reference to 'grade' inside of your 'feedback' function. At the moment, you are trying to reference 'grade' inside of your function but it sits outside the function. Therefore you don't need 'self.' before 'grade.

Hope that helps.

that makes sense, thank you! Also, I realized indentation matters a lot in Python!