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 trialZee Liu
2,027 PointsBeginner Inquiry - Python
I wonder why nothing is printed out in my code? called the function, but it shows <function Student.feedback at 0x7f98f2acfb70> only? What should I do to have the praise() and reassurance() content be printed out?
class Student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
def praise(self):
print("You inspire me, {}".format(self.name))
def reassurance(self):
print("Chin up, {}. You'll get it next time!".format(self.name))
def feedback(self):
if self.grade > 50:
return Student.praise()
else:
return Student.reassurance()
def __str__(self):
pass
b1 = Student("Tom", 60) print(Student.feedback)
1 Answer
Joseph Yhu
PHP Development Techdegree Graduate 48,637 Pointsif self.grade > 50:
return Student.praise()
else:
return Student.reassurance()
These should be self.praise()
and self.reassurance()
.
print(Student.feedback)
- The methods that the
feedback
method calls already have the print code, so you don't need to use print here. - You'd want to use
b1
instead ofStudent
. - The
feedback
method should be followed by parentheses.
Zee Liu
2,027 PointsZee Liu
2,027 PointsThank you so much! It works. I also wonder if I should use self.function() when I need to return or call another function in the recent function?