Mark Chesney11,499 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!
Steven Parker163,764 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.