Python Object-Oriented Python Dice Roller RPG Roller

Mark Chesney
Mark Chesney
10,926 Points

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
155,584 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.