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

A Fletcher
A Fletcher
6,987 Points

I cannot see what is wrong with my code

It appears I have used the correct syntax - any ideas?

first_class.py
class Student:
    name = "Your Name"


    def praise(self):
        print("Great work, {}!".format(self))
        return

What are the errors that you are seeing. Running this on my machine seems to work just fine

A Fletcher
A Fletcher
6,987 Points

Thanks for your response. Turns out there is nothing wrong with the code but I had been asked to return a string and not print. Thank you

1 Answer

Cameron Childres
MOD
Cameron Childres
Treehouse Moderator 11,715 Points

Hi A Fletcher,

Two things to note:

  • The task wants a string returned, not printed
  • The string needs to include the name attribute

You did a good job creating the method with the self argument. To access the name attribute you'll use self.name

All together it will look like this:

class Student:
    name = "Your Name"

    def praise(self):
        return "Great work, {}!".format(self.name)

Hope this helps! Let me know if you have any questions.

A Fletcher
A Fletcher
6,987 Points

Spot on - thank you!