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) Objects __init__

Instantiating error

slimey = Monster(5, 'sword', 'blue', 'glug') Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> slimey = Monster(5, 'sword', 'blue', 'glug') TypeError: object() takes no parameters

Hanley Chan
Hanley Chan
27,771 Points

Can you post the rest of your code. I believe the error is because your Monster class takes no parameters.

3 Answers

Hanley Chan
Hanley Chan
27,771 Points

Hi,

Looks like you only made a typo in your init function name so it is not overriding it correctly. You put int instead of init

It should be:

def __init__(self, hit_points, weapon, color, sound):
__author__ = 'Murungu'
class Monster:
  def __int__(self, hit_points, weapon, color, sound):
      self.hit_point = hit_points
      self.weapon = weapon
      self.color = color
      self.sound = sound

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

this is my class. and below is where im trying to access the class variables

__author__ = 'Murungu'
from monster import Monster
slimey = Monster(5, 'sword', 'blue', 'glug')
print(slimey.color)

Hanley Chan Thanks a lot, you saved my day...