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 Your first method

My code is working in my own environment, but not here. The error is about self, which I used correctly.

This is my code.

class Student: name = "Maryam"

def praise(self, st):
    if st in self.name:
        msg = "You're doing a great job, Maryam!"
        return msg
    return False

What is wrong with it?

first_class.py
class Student:
    name = "Maryam"

    def praise(self, st):
        if st in self.name:
            msg = "You're doing a great job, Maryam!"
            return msg

1 Answer

Josh Keenan
Josh Keenan
19,652 Points

Well it is because you are going about it in a way they don't want you to. When coding it is a good idea to remember the acronym KISS, Keep It Simple Stupid. When learning new things you can often over complicate them when the best solution is the simpler one.

class Student:
    name = "Your Name"

    def praise(self):
        return "You are doing a great job {}!".format(self.name)

All you have to do is return a string saying something encouraging and including the name, since we are using a method we can't access name without using self, since it belongs to the class. You can't hardcode your name in their, the treehouse interpreter is looking to see you passing in the self.name to the return statement somewhere, it can't tell what is or isn't a name, it only sees a string and that you aren't passing it what you need to, self.name