Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.