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

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!

Thank you so much that does help! :)