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 Class Methods

Charles Harpke
Charles Harpke
33,986 Points

Class methods question from the video: Attribute error

I replicated this error in both my Workspace and my own terminal:

>>> jubjub = Monster()
>>> jubjub.battlecry()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Monster' object has no attribute 'battlecry'
>>> 

Here is the code:

class Monster:
    hit_points = 1
    color = 'yellow'
    weapon = 'sword'
    sound = 'roar'

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

2 Answers

Charles Harpke
Charles Harpke
33,986 Points
def battlecry(self):
        return self.sound.upper()

was not properly indented.

It passes with no error.

This is my code:

class Monster(object):
    hit_points = 1
    color = "orange"
    weapon = "gun"
    sound = "roar"

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

And although I idented correctly, nothing changed. Why? I am using Python 2.7.