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,942 Points

SELF 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?

first_class.py
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
Michael Hulet
47,912 Points

I see a few problems here, but overall, this is relatively solid. There are 2 main issues, though:

  1. 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 on str. 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 function format(self.name), which in this case, is just the value of self.name. This is because you have a comma (,) in between "You are dong great{}" and format(self.name) when you're really trying to call the method format on the string "You are dong great{}" and pass it an argument of self.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 track

  2. Pay close attention to the instructions here. The challenge is asking you to return the string, but you're printing it instead. If you change it to a return, 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 gets formatted in as a different word after great

  • 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
rydavim
18,813 Points

When 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
nikel Hayo
1,942 Points

Thank you for in-depth explanation , after correcting to dot, the error just disappeared.