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 trialEmil Hejlesen
3,014 PointsWhy doesn't this work?
i just don't get i cause i can't find the error in this code
class Student:
name = "Your Name"
grade = 50
def praise(self):
return "You inspire me, {}".format(self.name)
def reassurance(self):
return "Chin up, {}. You'll get it next time!".format(self.name)
def feedback(self, grade):
if self.grade > 50:
self.praise()
else:
self.reassurance()
1 Answer
andren
28,558 PointsThere are two issues:
- You are not supposed to add
grade
as a class attribute, only as a parameter. That means that you should not define it at the top of the class, and not refer to it with theself
keyword. - You are asked to return the result of either the
praise
orreassurance
methods. You call those methods but you do not return their result.
If you fix those two issues like this:
class Student:
name = "Your Name"
# praise should not be defined as a class attribute
def praise(self):
return "You inspire me, {}".format(self.name)
def reassurance(self):
return "Chin up, {}. You'll get it next time!".format(self.name)
def feedback(self, grade):
if grade > 50: # Since grade is a parameter you don't use the self keyword
return self.praise() # Return the result of the method
else:
return self.reassurance() # Return the result of the method
Then your code will pass.
Emil Hejlesen
3,014 PointsEmil Hejlesen
3,014 Pointshey thx for the help i have tried this and it didn't work it said there was no grade in the class but thx for the help