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

Gary Gibson
Gary Gibson
5,011 Points

Keep getting an error in WorkSpaces when trying to import class Goblin(Monster).

Here is the code from the lesson:

import random

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


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.randint(self.min_hit_points, self.max_hit_points)
    self.experience = random.randint(self.min_experience, self.max_experience)
    self.color = random.choice(COLORS)
    self.weapon = kwargs.get('weapon', 'sword')
    self.sound = kwargs.get('sound', 'roar')

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

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

  def battle_move(self):
    return self.weapon.upper()

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

And here is the error I keep getting now:

``

Python 3.5.0 (default, Apr 5 2016, 17:53:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.

from monster import Goblin()
File "<stdin>", line 1
from monster import Goblin()
^
SyntaxError: invalid syntax

I was able to import the Goblin before. Not sure what I did to mess it up.

2 Answers

I can help! Try this:

>>> from monsters import Goblin

Moderator Edit: Changed from Comment to Answer

You are welcome!