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 trial

Python Object-Oriented Python (retired) Inheritance Subclasses

Constantin Lungu
Constantin Lungu
8,678 Points

Object is not callable

Hello, I keep getting this traceback error and I cannot figure out why. Can someone help? Thanks in advance!

import random

COLORS= ['yellow','blue','green','black'] class Monster(object): 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(self.min_hit_points, self.max_hit_points) self.experience = random(self.min_experience, self.max_experience) self.color = random.choice(COLORS)

for key,value in kwargs.items():
  setattr(self,key, value)

def battlecry(self): return self.sound.upper()


from monster import Monster
jubjub = Monster()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/treehouse/workspace/monster.py", line 12, in init
def init(self,**kwargs):
TypeError: 'module' object is not callable

2 Answers

Bart Bruneel
Bart Bruneel
27,212 Points

Hello Constantin,

On first view, your code is missing two things:

  • The double underscores around init are missing. The line should read:
def __init__(self, **kwargs):
  • When the program needs to chose a number between the max_hit_points and min_hit_points for self.hit_points the function random.randint() needs to be called. Same for self.experience.

I didn't test it, but I think this could maybe work.

Happy coding!