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 Project Breakdown

spencer tintorri
spencer tintorri
6,184 Points

Why do we include value in the D6 subclass?

The lesson presents this:

class D6(Die):
    def __init__(self, value=0):
        super().__init__(sides=6, value=value)

But it seems to work just fine with:

class D6(Die):
    def __init__(self):
        super().__init__(sides=6)

If we're not customizing anything about value in the D6 subclass, why include value?

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher
class D6(Die):
    def __init__(self, value=0):
        super().__init__(sides=6, value=value)

The code in the video shows the value is set to a default of zero in the init so you have the option of passing in a value for a D6 dice. Ex: d6 = D6(3) That value is then passed into the parent class to set the value. You're right, it's not needed for D6 to work. It is just giving the user the option of still being able to pass in their own value.