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 Subclass

Anthony David Victor Raj
Anthony David Victor Raj
1,602 Points

doesnt pass but says "does your 'dragon' class extend monster"

i dont know wat to do next

my_monster.py
import random

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


class Monster:
    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)

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

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

# passing the Monster class inside of parentheses, tells Python that Goblin is a subclass of monster, which means Goblin has all the attrs of Monsters unless modified within Goblinclass Goblin(Monster): 
    max_hit_points = 3
    max_experience = 2
    sound = 'squeak'

class Troll(Monster):
    min_hit_points = 3
    max_hit_points = 5
    min_experience = 2
    max_experience = 6
    sound = 'growl'
class Dragon(Monster):
    min_hit_points = 5
    max_hit_points = 10
    min_experience = 6
    max_experience = 10
    sound = 'raaaaaaaaaaaar'

2 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Anthony.

Where does all that code come from? I see a blank file to start the code challenge, and we are only asked to create a dragon class with one attribute only.

I imagine this would be around 3 lines of code in total.

Not sure if this question points to the right challenge though, because to solve the challenge linked to this question you would only need to import Monster from monster and than create the Dragon class which extends Monster.

Vitto