Session 5: Probability - Module B: Write a Program for Zombie Dice

1. Overview

Use what you've learned about unfair dice to create zombie dice.

2. Setting Up

Download zombieDice.py:

  1. Download the Python program zombieDice.py into your programs directory.

Start IPython:

  1. Open a terminal window.
  2. Change the directory to your programs directory with the cd command.
  3. Start IPython with the ipython command.
  4. From IPython, you can run your program by typing run zombieDice.py.

3. Writing a Zombie Dice Program

Now that you have played a few games of Zombie Dice and are familiar with the rules, you can write a program that rolls the dice with the same probability as the game.

Take a moment to think about what influences the result of each roll. Then, open zombieDice.py in gedit to view and edit the program. There are several lines throughout the program that must be completed before it will work. Look for comments in the code (lines starting with #) for hints.

As you're editing the file, consider the following lines:

pickDice = choice( allDice )
rollResult = choice( pickDice )

What do you think is in the pickDice variable after the first line is run?
How about rollResult after the second line is run?

4. Something's Not Right Here!

The individual dice rolls appear to behave as expected, but there is one aspect of the game that is still missing. Examine the code closely and compare it with actions you took each turn during the game. Can you determine what is missing? What would you need to change in the program to fix this?

If you're feeling brave, try making the changes to the code. Did your changes work as you expected?
Hint: Remember that the program starts from the beginning each time it is run. What do you need to add to the program in order to support multiple rolls?

Take a screenshot of your code, and answer these questions on your webpage.