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 Dice Roller RPG Roller

RPG Roller: class D20(Die) (task 1 of 2)

Just as a double-check, I've re-watched the Inheritance videos and learned a lot :)

I've noticed I can pass "Challenge Task 1 of 2" in two different ways. From the videos, I believe this is the better solution:

class D20(Die):
    def __init__(self):
        super().__init__()
        self.sides=20

The reason being, if someone were to hard-code into the Die class a six-sided die, then the code above would override it. However, this code below also passes the challenge.

class D20(Die):
    def __init__(self):
        super().__init__(sides=20)

Would anybody confirm my conceptual understanding of this? Thanks!

1 Answer

Steven Parker
Steven Parker
229,744 Points

While they both accomplish the same thing, your first example lets the base class create the instance with 2 sides, then you change it to 20.

I'd personally prefer the second example, because it has the base class set the sides to 20 to begin with.