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 trialhaakon Guttormsen
2,157 PointsHow to make a method that returns a positive message? (codechallenge)
I want to make a method that returns a positive message and which includes a name attribute. But I am not sure what is wrong with my code. Have anyone completed this challenge? Thanks for any help!
class Student:
name = "håkon"
def praise (self):
return ("I really like your hear today {}!"format.(name))
2 Answers
haakon Guttormsen
2,157 PointsThanks Nakalkucing. It works now. This is the correct code:
class Student:
name = "håkon"
def praise (self):
return ("I like your hair today {}".format(self.name))
nakalkucing
12,964 PointsYea! Happy coding håkon! :)
haakon Guttormsen
2,157 PointsThanks nakalkucing. I did the change but still I get a 'bummer' in the code challenge.
nakalkucing
12,964 PointsHello again! I tried the code with .format and got this error:
Bummer: NameError: name 'name' is not defined
and I noticed that you have "self" in the function. You should have "name".
def praise (self):
^
I know this doesn't entirely fix the problem, you'll get a new error at this point. But this one is a little more explicit.
If you need any more help on this let me know. Best, Nakal :)
nakalkucing
12,964 Pointsnakalkucing
12,964 PointsHi haakon Guttormsen! For one thing, you have:
format.
It should be:
.format
Hope this helps! :)