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 trialMUZ140515 Herbert Chirwa
2,589 Pointsi don't get what am supposed to do on challenge 4 of 4 hack n slash
help, totally confused on this challenge
from character import Character
class Warrior(Character):
weapon = "sword"
def rage(self):
self.attack_limit = 20
class some_class:
a_value = 20
def some_method(self):
return self.a_value
1 Answer
Dan Johnson
40,533 PointsThere's a special method dealing with the response to a string conversion. Here's its signature:
def __str__(self):
# Return the formatted string here.
MUZ140515 Herbert Chirwa
2,589 PointsMUZ140515 Herbert Chirwa
2,589 Pointsstill facing challenges man can you further elaborate
Dan Johnson
40,533 PointsDan Johnson
40,533 PointsYour class should have this structure:
The format string you could use could be something like this:
desc = "Warrior, {weapon}, {attack_limit}"
You could then fill out those placeholder using the format method on that string, assigning weapon and attack_limit to their corresponding property/attribute, and then returning it from
__str__
.