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 Intro to Inheritance

Armando Gonzalez
Armando Gonzalez
4,161 Points

Console problems

I am using pythonista 3 for iOS. After setting the monster class as done in the video, my console still wants me to add the attributes into the ().

I am doing everything Kenneth is saying to do. And I noticed that in workspaces, I do not receive the same error message.

Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: init() missing 4 required positional arguments: 'hit_points', 'weapon', 'color', and 'sound'

Here is my code:

import random

COLORS = ['red', 'purple', 'blue', 'magenta', 'black', 'brown'] #made a constant array of colors to choose from

if you leave def attributes blank, yiur have to redo them

if you will them in with (), it will have same results?

you can remove everything and use kwargs.get (**kwargs)

class Monster: min_hit_points = 1 #these are the monster class defaults 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) #min, max, and colors are defined above

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


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

Markdown readable

import random

# made a constant array of colors to choose from
COLORS = ['red', 'purple', 'blue', 'magenta', 'black', 'brown']

# if you leave def attributes blank, yiur have to redo them
# if you will them in with (), it will have same results?
# you can remove everything and use kwargs.get (**kwargs)

class Monster: 
    # these are the monster class defaults 
    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) #min, max, and colors are defined above

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


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

1 Answer

Lisa Ess
Lisa Ess
7,193 Points

I have this same issue. Code is correct, but same error.