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 trialSuleiman Abdurozikov
2,943 PointsI can t figure out what is wrong !!!
I need to write class and weapon and attack in str , Please help !!
from character import Character
class Warrior(Character):
def __init__(self,**kwargs):
self.weapon = kwargs.get('weapon','sword')
self.attack = self.rage()
def rage(self):
self.attack_limit = 20
def __str__(self):
print("{},{},{]".format(self.__class__name__,self.weapon,self.attack))
2 Answers
john larson
16,594 Pointsfrom character import Character # <-- a space after the import would make it more readable
class Warrior(Character):
# here it is asking for weapon to be = to sword
# you really went to town with this block, but the challenge did not ask for an init
# you could take the init block out entirely
def __init__(self,**kwargs):
self.weapon = kwargs.get('weapon','sword')
self.attack = self.rage()
# this block looks fine
def rage(self):
self.attack_limit = 20
def __str__(self): # <-- this line is ok
# 1: here it should be return not print (I'm pretty sure, at least that's how it passed for me)
# 2: you really only need to format self.weapon and self.attack_limit (note* you have self.attack)
# 3: I see what you are doing for the name of the class, which is great and it might have worked that way
# (I didn't check if it would work that way if done properly)
# but look at your 3rd {}
print("{},{},{]".format(self.__class__name__,self.weapon,self.attack))
# I just tried cleaning that line up and I still couldnt get it to pass
# this is what I used
return "Warrior, {}, {}".format(self.weapon, self.attack_limit)
# again, you really went to town trying to get all the stuff that was presented, and that's awsome
# sometimes the challenges are simpler than that, and it gets confusing what they are looking for
Way to go, you obviously put effort into that :D
Suleiman Abdurozikov
2,943 Pointsthank you very much!!