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

haakon Guttormsen
haakon Guttormsen
2,157 Points

How 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!

first_class.py
class Student:
    name = "håkon"
    def praise (self): 
        return ("I really like your hear today {}!"format.(name))
nakalkucing
nakalkucing
12,964 Points

Hi haakon Guttormsen! For one thing, you have:

format.

It should be:

.format

Hope this helps! :)

2 Answers

haakon Guttormsen
haakon Guttormsen
2,157 Points

Thanks 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
nakalkucing
12,964 Points

Yea! Happy coding håkon! :)

haakon Guttormsen
haakon Guttormsen
2,157 Points

Thanks nakalkucing. I did the change but still I get a 'bummer' in the code challenge.

nakalkucing
nakalkucing
12,964 Points

Hello 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 :)