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

Lukas W.
Lukas W.
3,013 Points

connot import name 'Dragon'

Hi everyone,

I have a rather simple problem. Still, I am not able to fix it and I don't know why. When I try to import the Dragon or the Goblin class the following error occurs:

"File "<stdin>", line 1

from monster import Dragon()"

Might someone give me a hint, what is wrong? Thank you very much!

Here is my code:

import random

COLORS = ['yellow', 'red', 'blue', 'green']


class Monster:
  min_hit_points = 1
  max_hit_points = 1
  min_experience = 1
  max_experience = 1
  color = 'yellow'
  weapon = 'sword'
  sound = 'roar'

  def __init__(self, **kwargs):
    self.hit_points = random.randint(self.min_hit_points, self.max_hit_points)
    self.weapon = random.randint(self.min_experience, self.max_experience)
    self.color = random.choice(COLORS)

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

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

class Dragon(Monster):
  pass

class Goblin(Monster):
  max_hit_points = 3
  max_experience = 2
  sound = 'squeak'

2 Answers

Josh Keenan
Josh Keenan
20,315 Points

You have one typo in your code firstly:

for key, value in kwargs.items():
      stettr(self, key, value)              # <-- stettr? setattr!

Where are you trying to import it as well, add that code!

Also when importing the syntax is:

from monster import Dragon()     # <-- not this

from monster import Dragon        # <-- this
Lukas W.
Lukas W.
3,013 Points

Thank you very much! Works now!