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 trial

Python

object 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)
John Reilly
John Reilly
10,800 Points

Learning 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.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

I 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
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Very 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)

thanks it worked