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!
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 trial
MUZ140239 Tinashe Banguwangu
2,825 Pointsobject oriented programming
When Warrior is converted to a string, the string should be like "Warrior, <weapon>, <attack_limit>". Update your class to produce this string using values from the instance: please help me am stuck: here is my code___:
from character import Character
class Warrior(Character):
weapon = 'sword'
def rage(self):
self.attack_limit = 20
return self.attack_limit
def __str__(self):
return "{}, {}, {}".format(self.__class__.__name__,
self.weapon,
self.attack_limit)

Chris Freeman
Treehouse Moderator 68,332 PointsI gather that the missing __
in def __str(self):
is being swallowed by the formatting. I recommend using surrounding your code in triple-back-quotes as mentioned in the Markdown Cheatsheet.
2 Answers

Chris Freeman
Treehouse Moderator 68,332 PointsVery Close! Your string method needs to be named __str__
as in `def __str__(self):
def __str__(self): # <-- corrected method name
return "{}, {}, {}".format(self.class.name_, self.weapon, self.attack_limit)

MUZ140239 Tinashe Banguwangu
2,825 Pointsthanks it worked
John Reilly
10,800 PointsJohn Reilly
10,800 PointsLearning Python at the moment myself but shouldn't the return be
'Warrior, {}, {}'.format(...)
Sometimes I've had issues with the Challenges and It has been issues of being too smart for what its asking. Really sorry if this is useless help.