Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Instant Objects Method Interactivity

Jake Williams
Jake Williams
2,673 Points

Method interactivity challenge.

I'm getting an exception but I don't know why or how to fix it. The exception says " '>' not supported between instances of 'Student' and 'int'.

first_class.py
class Student:
    name = "Jake"

    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

Hi Jake!

Your feedback function needs some tweaking.

In Python, parentheses are not generally relied on as much as they are in Javascript, so I would type the code more like this:

class Student:
    name = "Jake"

    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: # here you just need to compare the grade, so don't use self on this line of code
            return self.praise()
        else:
            return self.reassurance()

But you do need the parentheses for both return statements or you'll return a reference to the function and not the desired resulting text.

Which looks something like this:

<bound method Student.praise of <__main__.Student instance at 0x7f3106bbb680>>

Does that make sense?

More info:

https://www.geeksforgeeks.org/python-invoking-functions-with-and-without-parentheses/

I hope that helps.

Stay safe and happy coding!

BTW,

I tested the code here:

https://www.katacoda.com/courses/python/playground

Using this code:

class Student:
    name = "Jake"

    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: # here you just need to compare the grade, so don't use self on this line of code
            return self.praise()
        else:
            return self.reassurance()


Jake = Student()
print( Jake.feedback(30) )
print( Jake.feedback(70) )

Again, I hope that helps.

Stay safe and happy coding!

Jake Williams
Jake Williams
2,673 Points

Thank you so much that does help! :)