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 Python (retired) Hack-n-Slash Warriors! Come Out and Play-ay!

when warrior is converted to a string

i cannot seem to notice where im going wrong.

warrior.py
from character import Character
class Warrior(Character):
  pass
  weapon = 'sword'

  def rage(self):
    self.attack_limit = 20

  def __str__(self):  
    return "{} {}, weapon {},attack_limit {}".format(self.__class__, 
                                                     self.weapon, 
                                                     self.attack_limit)

4 Answers

Jeremy Fisk
Jeremy Fisk
7,768 Points

I think they actually want the string "Warrior" instead of the {} {} at the beginning of your return statement...

its not working Jeremy

Jeremy Fisk
Jeremy Fisk
7,768 Points

Additionally, they do not want the strings "weapon" and "attack limit" included in your return statement ....

from character import Character class Warrior(Character): weapon = 'sword'

def rage(self): self.attack_limit = 20

def str(self):
string = "{}, {}, {}".format(Warrior.name, self.weapon, self.attack_limit) return string

Dan Johnson
Dan Johnson
40,532 Points

The __class__ attribute deals with the class type. You were probably looking for the __name__ attribute:

"{}, {}, {}".format(Warrior.__name__, self.weapon, self.attack_limit)

You can also drop the pass since you have a class definition.