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

nikel Hayo
nikel Hayo
1,943 Points

Python class

What’s wrong with the code? Can you help?

first_class.py
class Student():
    name = "Your Name"
    def praise(self):
        print(" I REALLY LIKE OUR HAIR,{}".format(name))
from first_class import Student()
me=Student()
me.name="NIHAT"
print(me.praise())

3 Answers

Some hints:

  • no need to import since you are in the same file.
  • in fact you should remove all code from the import statement on down
  • your praise method should return the string not print it
  • In your praise method you will want to use the instance with name: self.name
nikel Hayo
nikel Hayo
1,943 Points

yea, I did it. self.name did the trick. thank you very much.

nikel Hayo
nikel Hayo
1,943 Points

even though the code below works at Workspace, the challange at the track constanly gives error"Oh no you have forgotten Self argument in your praise method". is there any error or is the just website's annoyance?

class Student: name = "Your Name" def praise(self): print("You are doing great {}",format(self.name)) me=Student() me.name="nikel" me.praise()