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

Please help identify the issue with my code. Related to Challenge "write your first method" under Object-Oriented Python

Briefly, define a class Student with an attribute name and a method that takes an instance and prints it out in a positive statement. I did the following and it works for me but won't pass the challenge successfully. I don't know why, so please help.

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

    def praise(self):
        return print("You're doing a great job, {}!".format(me.name))

me = Student()
me.name = "Jacinta"
Student.praise(me)      # alternatively: me.praise()

Whenever I test the code in my Workspace, it outputs whatever me.name I give it successfully. Example:

You're doing a great job, Jacinta!

2 Answers

Steven Parker
Steven Parker
231,269 Points

Here's a few hints:

  • "me" is the name of your test instance, it should not be referenced in the function itself
  • the function should use "self" to access any class values
  • you need to return the formatted string directly, you won't need to "print" anything
  • for the challenge, you only need to define the function — no need to create an instance or call it

Thanks. I find the second hint is the key for me.

class Student: name = "Your Name"

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