Creating a Dice Class

Have you played a game where you used dice? Let’s create a Die class so that if we lose our physical dice we can still play. A die is one of a pair of dice.

Q-1: What attributes (data) would an object of the Dice class need to know? What questions should you be able to ask about it?

Q-2: What behaviors (methods) would we expect a dice class to have?

We would expect to be able to roll a die and get the value from the last roll. When we roll a dice we pick a random number from 1 to 6. Let’s store all the values that were rolled in a list, roll_history. We will add each value rolled to the end of the roll_history list and return the value from the roll method.

You have attempted of activities on this page