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!

fahad lashari
fahad lashari
6,771 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

warrior.py
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__,
                                   Character().__class__.weapon,
                                   Character().__class__.attack_limit)

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

1 Answer

Steven Parker
Steven Parker
216,057 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