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

Joseph Michelini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Michelini
Python Development Techdegree Graduate 18,692 Points

Where is the attribute "sides" stored?

When we initialize d6 as a D6 object, a subclass of Die, and pass in the sides attribute, where is it stored? When I go to check the sides attribute on d6 there isn't one, according to the terminal.

Does this have something to do with us not explicitly writing self.sides = sides in the parent class? And if so, why don't we do that?

Thanks in advance!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Great question! In the Die class, the parameter sides is used to initialize the value attribute. It is not needed after that since the die, once cast, does not change value. So once the value attribute is set, sides is discarded.

But you bring up an interesting point. Say you did want to add functionality that let the die "reroll" itself, then the die would need to remember how many sides were specified. In this case, an assignment to self.sides = sides would be needed to preserve this parameter value, as you mentioned.

Post back if you have more questions. Good luck!!