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 trial

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

i don't get what am supposed to do on challenge 4 of 4 hack n slash

help, totally confused on this challenge

warrior.py
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
Dan Johnson
40,533 Points

There's a special method dealing with the response to a string conversion. Here's its signature:

def __str__(self):
    # Return the formatted string here.

still facing challenges man can you further elaborate

Dan Johnson
Dan Johnson
40,533 Points

Your class should have this structure:

from character import Character

class Warrior(Character):
  weapon = "sword"

  def __str__(self):
    # Return the formatted string here.

  def rage(self):
    self.attack_limit = 20

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__.