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 trialRichard Berman
2,695 PointsPassing Warrior as __str__
I'm trying to pass the below code, but I keep getting the response that Task 1 is not longer passing. Any idea what's wrong here?
from character import Character
class Warrior(Character):
weapon = 'sword'
def rage(self):
self.attack_limit = 20
def __str__(self):
print "Warrior, {}, {}".format(self.weapon, self.attack_limit)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! You're doing really well here, but there are a couple of things going on. First, it says that the first step is no longer passing because you've included a print method with no parentheses. This is introducing a syntax error. However, the challenge is not looking for you to print this string, it's wanting you to return the string. Take a look:
def __str__(self):
return "Warrior, {}, {}".format(self.weapon, self.attack_limit)
This will return the string it's looking for.
For future reference: if we had wanted to print it, it would've looked like this:
def __str__(self):
print("Warrior, {}, {}".format(self.weapon, self.attack_limit))
Note the set of parentheses around the string to be printed.
Good luck and hope this helps!