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

Python Object-Oriented Python (retired) Hack-n-Slash Warriors! Come Out and Play-ay!

fahad lashari
fahad lashari
7,693 Points

Code challenge help please

I am not really sure how to solve this problem. The question asks to produce a string which looks like "Warrior, <weapon>, <attack_limit". However once I achieve this, it expects specific values on these attributes. I am completely lost as to what piece of this puzzle I am missing.

Any help would be greatly appreciated.

Kind regards,

Fahad Lashari

from character import Character
class Warrior(Character):
    weapon = "sword"
    attack_limit = 20
    def rage(self):
        self.attack_limit = 20

    #def __init__(self, **kwargs):
        #for key, value in kwargs.items():
            #setattr(self, key, value)

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

    # Bummer! Expected "Warrior, axe, 40", got "Warrior, sword, 20".

1 Answer

Steven Parker
Steven Parker
228,039 Points

You're getting too fancy, keep it simple.

  • the way you get "Warrior" works, but that can simply be a literal part of the format string
  • in an earlier task you set attack_limit. You can access it the same way to pass it to format
  • you can also access the weapon the same way as attack_limit