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 trialTerry Sagas
2,354 Pointsneed help
keep getting errors, tell me what's wrong with my code thanks in advance
import random
COLORS = ['yellow', 'red', 'blue', 'green',]
class Monster: min_hit_points = 1 max_hit_points = 1 min_experience = 1 max_experience = 1 weapon = 'sword' sound = 'roar'
def __init__(self, **kwargs):
self.hit_points = random.randint(self.min_hit_points, self.max_hit_points)
self.experience = random.randint(self.min_experience, self.max_hit_experience)
self.color = random.choise(COLORS)
for key, value in kwargs.items():
setattr(self, key, value)
def battlecry(self):
return self.sound.upper()
class Goblin(Monster):
max_hit_points = 3
max_experience = 2
sound = 'squeak'
class Troll(Monster):
min_hit_points = 3
max_hit_points = 5
min_experience = 2
max_experience = 6
sound = 'growl'
class Dragon(Monster):
min_hit_points = 5
max_hit_points = 10
min_experience = 6
max_experience = 10
sound = 'raaaaaaaaaaaaaar'
Alexander Davison
65,469 PointsPlease make your answer a real "answer" by copying-and-pasting your comment and pasting it into the answer box below then posting.
If you make your "message" an "answer" instead, it enables other students to upvote your answer and give you a best answer.
Keep in mind that upvotes and best answers give you bonus points!
Ammar Fatihallah
7,417 PointsThank you Alexander :)
1 Answer
Ammar Fatihallah
7,417 PointsYou have a typo in the__init__
. which is in this line self.color = random.choise(COLORS)
. it should be choice and not choise.
Alexander Davison
65,469 PointsUpvoted
Terry Sagas
2,354 Pointsthanks but still get an error like:
import monster Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/treehouse/workspace/monster.py", line 6, in <module> class Monster: File "/home/treehouse/workspace/monster.py", line 26, in Monster class Goblin(Monster): NameError: name 'Monster' is not defined
Ammar Fatihallah
7,417 PointsHey terry, are you still having the error ? if so can you post a screenshot so i can see it clearly. Thanks.
Terry Sagas
2,354 Pointsdon't know how to post a screen shot but I asked another question so you look at that one its more clear
Ammar Fatihallah
7,417 PointsI left you an answer there, hope it's helpful :)
Ammar Fatihallah
7,417 PointsAmmar Fatihallah
7,417 PointsYou have a typo in the
__init__
. which is in this lineself.color = random.choise(COLORS)
. it should be choice and not choise.