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 trialnikel Hayo
1,943 PointsSELF ERROR
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 dong great{}",format(self.name))
me=Student()
me.name="nikel"
me.praise()
3 Answers
Michael Hulet
47,913 PointsI see a few problems here, but overall, this is relatively solid. There are 2 main issues, though:
This technically doesn't throw an error, but that's just because
format
is also defined as a global function instead of just a method onstr
. Regardless, when this code runs as-is, Python prints out the string"You are dong great{}"
, and then prints out the result of calling the global functionformat(self.name)
, which in this case, is just the value ofself.name
. This is because you have a comma (,
) in between"You are dong great{}"
andformat(self.name)
when you're really trying to call the methodformat
on the string"You are dong great{}"
and pass it an argument ofself.name
. This is done with a period (.
) instead of a comma (,
). You actually do a great job of this later down in the file in the last couple lines, so if you do here what you did there, you'll be on the right trackPay close attention to the instructions here. The challenge is asking you to
return
the string, but you'reprint
ing it instead. If you change it to areturn
, I think you may have all you need to pass this challenge. Great job!
If it doesn't pass after that, there are a couple more things you could try:
Currently, once you run the code after making the aforementioned fixes, it'll print out the string
"You are dong greatnikita"
. The fact that there isn't a space before your name might throw off the challenge checker, so be sure it getsformat
ted in as a different word aftergreat
You don't actually need any of the code after the
class
to pass the challenge. You can (and maybe should) delete the last 3 lines, as they might throw the challenge checker off a bit
rydavim
18,814 PointsWhen I run your code in workspaces, I'm not getting the expected result. It looks like you're printing a string and then the name.
class Student:
name = "Your Name"
def praise(self):
print("You are dong great{}",format(self.name)) # . in place of ,
me=Student()
me.name="nikel"
me.praise()
# That gets me the string *and* the name value.
# You are dong great{} nikel
You've got the right idea, you just need to remember to use .
notation. format()
is a method, rather than an argument, so you should use a dot in place of the comma. Give that a try, and if you're still stuck let me know and we can walk through a solution. Good job, and happy coding!
nikel Hayo
1,943 PointsThank you for in-depth explanation , after correcting to dot, the error just disappeared.