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 trialfahad lashari
7,693 PointsCode 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__,
Character().__class__.weapon,
Character().__class__.attack_limit)
# Bummer! Expected "Warrior, axe, 40", got "Warrior, sword, 20".
1 Answer
Steven Parker
231,271 PointsYou'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