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

Jon Helmus
Jon Helmus
7,312 Points

What am i getting wrong here?

yet again, another problem i am having an issue understanding.

first_class.py
class Student:
    name = "Jon"

    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 praise
        return reassurance
Jon Helmus
Jon Helmus
7,312 Points

Alright, I need you make a new method named feedback. It should take an argument named grade. Methods take arguments just like functions do. You'll still need self in there, though. If grade is above 50, return the result of the praise method. If it's 50 or below, return the reassurance method's result.

4 Answers

Vishal's is correct, but it isn't efficient. It's simpler to call the actual methods that achieve these same results. You use "self." with the praise() and reassurance() methods since they're called on the instance of "Student."

Also, just a sidenote, your operators for "greater than or equal to" are reversed and if you ran that, you'd get a syntax error. Greater than or equal is signified by ">=" and likewise with "less than or equal to" being "<=."

Here's the code:

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()
        return self.reassurance()
Jon Helmus
Jon Helmus
7,312 Points

Thank you everyone. I'm shaking the spiders outta my brain and getting back into the swing of python things.

Cameron Sprague
Cameron Sprague
11,272 Points

I was struggling with this concept too. This worked for me. Ask me any questions about the code below and I will see if I can help.

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 think you're the only one that get the instructions right non of the above use and else and you're the underrated comment

Vishal Gali
Vishal Gali
5,761 Points

Your issue is just some minor misunderstanding first the question explicitly says result of praise and reassurance not he actual method second grade is not an attribute for self, it is a separate argument. the question said if grade is below or above 50, which means you only need to put grade in.

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 "You inspire me, {}".format(self.name)
        return "Chin up, {}. You'll get it next time!".format(self.name)
Khem Myrick
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Khem Myrick
Python Web Development Techdegree Graduate 18,701 Points

Thank you! I was getting caught up trying to make grade an attribute of student. When it told me grade wasn't an attribute of student, I assumed I was supposed to make it into an attribute, rather than having it be its own argument. (Calling the praise() and reassurance() methods worked just fine, when I stopped insisting on checking self.grade rather than just grade).

Sanjay Singh
PLUS
Sanjay Singh
Courses Plus Student 168 Points

I add my one-liner code if someone prefers:

class Student:
    name = "John"

    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):
        return self.praise() if grade > 50 else self.reassurance()
mourad marzouk
mourad marzouk
5,560 Points

why does it have to be self.praise or self.reassurance?