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 trialFrank Campos
4,175 PointsI dont understand, how can I canculate the sides and value in class Die?
we have in the init of class Die, sides and value. the value is 2 what does it mean?I don't if I am wrong but it does mean that the die has only two sides "faces" on the die. And with value , does it take the number of side(face) of the Die?
1 Answer
Jon Mirow
9,864 PointsHi there!
Hopefully you've now moved past this point, but just in case, the value in this example is the number you get as the result of a roll.
For example, a dice found in most board games has 6 sides or faces. Which ever one is facing "up" towards the player is the current value of the dice.
In this example, every instance of a Dice must have a number of sides (faces) declared at creation - which makes sense right? if you have a dice, you know how many sides it has, and that doesn't change. BUT you don't know its value until you roll it.
Here Kenneth has included a roll into the __init
__ method, so whenever you create a dice, you get a random value - much like picking your dice out of a bag or box to use it. That's pretty useful, but it might make it hard to test your game if you don't always know what the value of the dice is. That's where the value parameter comes in. It has a default value of 0 so it's ignored by the or operator (0 is falsey in python) but we can overide it so that creating a dice will give it a set value (any number not 0 is truthy)
hope it helps/is useful to someone else who finds this :)
Frank Campos
4,175 PointsFrank Campos
4,175 PointsThank you a lot Jon Mirow .
To recap,
*Sides == faces
*value == number facing 'up' towards the player
I was confused because the first dice that we created it has only two sides(faces) as result we had only two values to chose, 1 and 2. I did not understand that is possible to have a dice with only with two sides!!!
nicole lumpkin
Courses Plus Student 5,328 Pointsnicole lumpkin
Courses Plus Student 5,328 PointsThanks Jon! I'm someone else who found this so helpful !! These are the small yet wholly significant details that will cause me (and I suspect others) to spend a ton on time on one video. I've never seen zero used quite in the way!