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 trialEdward Torres
6,158 PointsDon't know what is wrong with my code.
It just keeps saying try again. Please help.
from character import Character
class Warrior(Character):
weapon = 'sword'
string = 'Warrior'
def rage(self):
self.attack_limit = 20
def __str__(self):
string = "{}, <{}>, <{}>".format(string, weapon, rage())
return string
1 Answer
Dan Johnson
40,533 PointsThe rage method returns no value, so it won't pass anything in to the format call. Use attack_limit directly to get the value.
Also remember that when you're accessing properties or methods of a class that you'll need to use self
.
Brian Fuller
6,699 PointsBrian Fuller
6,699 PointsJust another comment: in str , why define the local variable string, if all you're going to do is return it on the next line?
Just use
return "{}, {}, {}".format(self.string, self.weapon, self.attack_limit)