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 trialjp28
3,413 PointsEverything should be working, but is not....
The code should be working but treehouse is telling that there's a mising 'self' in the praise method
class Student:
name = "Nico"
def praise(self):
print ("You're doing a great job, {}!".format(self))
nick = Student()
nick.praise()
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're doing great, but there's a couple of things going on here. Unfortunately, the Bummer! message you're getting for this is a bit misleading. The first problem is that you're printing the string, but the challenge asks you to return the string. Also, you did include self
as a parameter, but you're trying to format the string with self
instead of the name
property of self. Take a look:
def praise(self):
return "You're doing a great job, {}!".format(self.name)
Here we have the praise method which takes an argument of self. We return the string with a placeholder and format the placeholder with the value stored in the self.name
property.
Also, the challenge does not ask you to create any instances of this class, nor call the method on this class. Treehouse is going to do that part for you. Hint : Challenges can be very strict and it's a good idea to try not to do anything that isn't explicitly asked for. Even if functional, it can cause the challenge to fail.
Hope this helps!
jp28
3,413 Pointsjp28
3,413 PointsThank you!!! I'll be more carefull the instructions...
Clifford Gagliardo
Courses Plus Student 15,069 PointsClifford Gagliardo
Courses Plus Student 15,069 PointsI don't understand why we have to use self.name and not just .format(name)
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi, Clifford Gagliardo! I also had a hard time wrapping my head around this at first. I'm going to show you a slightly more complex example, but I feel like it helps clarify what "self" actually does. This concept didn't start becoming more clear to me until I had examples that had multiple instances of the same object. I think you and I can agree that we are both students of Treehouse and we do share some characteristics, but we are both unique. Take a look at the example I made:
In this example name is a property of the Student class. In fact, it's the only property at all. If this were a real world scenario we'd likely expect the student to have an ID (because there could be more than one John Smith, after all), and a lot of other generic information about the student.
In the lines where I define
me
andyou
, I'm creating an instance of that class. You are one student and I'm another. We have different names. I made a separate method that takes an instance of itself and an instance of another student. So we can say hello to each other!I feel like this might become more obvious when you see two separate instances of the same class used in conjunction.
Hope this helps!
The two lines printed will be:
Hi there, Clifford! My name is Jennifer. Hi there, Jennifer! My name is Clifford.