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 trialPeter Donaghy
3,875 PointsWhy am I getting this error message?
When I run this code I get the error message
"Oh no! You forgot the self
argument in your praise
method"
But as far as I can tell I have included the 'self' argument in the parenthesis in the method. I don't understand what I am doing wrong?
Any ideas?
Thanks.
class Student:
def praise (self):
name = "Pete"
print("Great job{}!".format(name))
me = Student()
me.praise()
3 Answers
Pedro Cabral
33,586 PointsFor two reasons:
1) At the beginning of the challenge, there is a code-stub where name is given as a class attribute/property. You should leave it be. At the moment you have moved it inside your method, making it a local variable.
2) Your method should return a message. At the moment it doesn't return, it prints it instead.
Remember that you call a class attribute via self.attributename
Steven Parker
231,248 PointsThe challenge asks that "*The method should return a positive message, it won't need to "print" anything.
And the "self" prefix should be used when referencing the instance attribute "name". And that attribute should be defined at the class level, outside of the method (as provided in the original code).
Peter Donaghy
3,875 PointsThanks both for your replies -. I realised my mistake soon after posting this question. Should have used self.name rather than move the attribute called name.