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 trialMUZ140502 Natasha Hove
3,732 PointsMake a new Warrior method called rage that sets attack_limit to 20.
I wrote the code below and I'm getting 'Try Again' error..What am i supposed to do??
def rage(self): attack_limit=20 return Warrior.rage
from character import Character
class Warrior(Character):
weapon = 'sword'
def rage(self):
attck_limit=20
return Warrior.rage()
#pass
1 Answer
John Reilly
10,800 PointsHello Natasha,
I'm learning at the moment as well so don't think this is definitely the correct solution.
The function "def rage(self):" takes the input of self (object) and you have not referenced that inside the function, which means that you have just created a variable called attack_limit in a function which never leaves the function as you do "return warriors.rage()".
What you need to do is reference the object in the function using the input of the object "self". You will not need to return anything as you are just adding more information (attack_limit = 20) to the object which is already created.
def rage(self):
self.attack_limit = 20
Sorry about the code, not yet figured out how to represent it in this comment section. Markdown cheatsheet doesn't seem to help me (Thanks for Fixing it William Li, feel like an idiot for not being able to do it! I understand now, maybe I should read more next time and not just skim read). Hope what I've said has helped, if not sorry :) and hope someone more useful comes along and corrects us both!
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 Pointsedited the code block for proper syntax highlighting.