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 trialevtccgltph
1,892 PointsIs the code at 2:36 wrong?
I ran the code below in an IDE (not workspaces) with both python 2 and 3 and it gives an error. Shouldn't dodge_limit in the dodge method be self.dodge_limit, and shouldn't attack_limit in the attack method be self.attack_limit?
import random
class Combat:
dodge_limit = 6
attack_limit = 6
def dodge(self):
roll = random.randint(1, dodge_limit)
return roll > 4
def attack(self):
roll = random.randint(1, attack_limit)
return roll > 4
I added this code below the above code to see if the above code works. It doesn't seem to work.
object1 = Combat()
print(object1.dodge())
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsYou are correct. Kenneth hits the same error and corrects it at time 4:15 in video. An advantage of watching Kenneth code live in the video is seeing common mistakes everyone makes and how to correct them.