Lab 5
Random Objects


Preliminary Setup

For this lab, you will be creating an object-oriented (OO) program to play a simple dice game. Start with the following:

  1. Create a PyCharm project. Make sure you use your name somewhere in the project name (like CassLab5).
  2. Create, where you will put the main() function.
  3. Create a module where you will put the Dice class.1

Step I: Write the Dice class

In the dice module, write the Dice class. A Dice object should have two properties/attributes: the number of sides the dice has, and the current value showing on the dice. These properties should be attributes in your class (also known as instance variables).

Add the following methods:

Step II: Write main

In the main module, write the main() function to play a simple game according to the following rules:

  1. The game uses a D6 and a D12 (6-sided and 12-sided dice).
  2. On each turn, we roll both dice.
  3. The game is won if one of the dice shows a value that's exactly twice the value of the other.

Your main function should create variables for the two dice: each should be an object of type Dice.

Your program should use the input function to ask the user to hit return before each turn. After each turn, the program should check if we've won. If we've won, print a message saying so and end the program.

Step III: Add a default [Extra Credit]

Now, go back and modify the Dice class so that the default number of sides is 6, so that if we ask to create a dice without specifying the number of sides, we will get a D6. Modify main() so it uses this default as appropriate.

How to turn in this lab

Before turning in any program in this class, remember this mantra:

Just because it works doesn't mean it's good.

Part of your grade will also come from things like how understandable and readable your code is. You will also be graded on the neatness, presentation, and style of your program code.

For all labs, turn in only an electronic version. Please compress your program and email the zip file or tarball to me at

Ask for help if you're having problems!

1. I've checked, and "Dice" is an acceptable singular form. If this bothers you because you consider "Dice" as plural only, then you should instead create a "Die" class. Classes should be named with singular nouns.