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 trialAdam Kroner
1,460 PointsStruggling with classes and methods...
Not understanding the use of self in this concept.
This class should look familiar!
I need you to add a method name praise. The method should return a positive message about the student which includes the name attribute. As an example, it could say "You're doing a great job, Jacinta!" or "I really like your hair today, Michael!".
Feel free to change the name attribute to your own name, too!
class Student:
name = "Adam"
def praise(self):
print("You're doing a great job, {}!".format(name))
1 Answer
Ronald Kratochwill
11,213 Pointsclass Student:
name = "Adam"
def praise(self):
# Parameters must be called with self in front of them
# I missed an instruction in the challenge it wanted a
# return statement instead of a print
return "You're doing a great job, {}!".format(self.name)
# Create an instance of the class
student = Student()
# Use method of instance! It is wrapped in print so you can see result
print(student.praise())
Ronald Kratochwill
11,213 PointsRonald Kratochwill
11,213 PointsI have updated the answer and checked it through the challenge. I missed that they wanted to have the statement returned not printed. I have updated my code. I did submit it too in order to make sure. Sorry!
Ronald Kratochwill
11,213 PointsRonald Kratochwill
11,213 PointsI also did not mean to delete my old post that was an accident.
Adam Kroner
1,460 PointsAdam Kroner
1,460 PointsThank you and no worries! I see where I was going wrong.