Polyhedral dice

Polyhedral dice

Rolling a 6, 8, 10 and 12 sided dice.


Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

Knowledge Organiser

Command summary

The new commands used in this program and others that may be useful. Select them below to learn more:

import x

Includes functions from the library ‘x’ in your program. E.g. import random will give you access to use commands in the ‘random’ library. Importing libraries allows you to extend a programming language with new commands that are not already built-in to the language. Libraries are created by programmers for other programmers to use in their programs.


Sets the seed x to be used by the random number algorithm. The value of x can be omitted to use the current time as the seed number instead. Using the time of day as the seed gives the impression of truly random numbers.

random.randint(x, y)

Generates a random number between x and y inclusive.


Questions to think about with this program to check your understanding:

Item question

Identify two constants in the program that could be variables instead.


The numbers 1 and 6 could be constants in this version of the program although that would limit the program to only simulating the roll of a six-sided dice.

Structure question

State what the two parameters are used for in the randint command in line 13.


The lowest and highest number that can be generated by the random number algorithm. Any number between or including these two values could be generated.


Success Criteria

Change the program so that it:

  1. Asks the user what sided dice to roll in the main program.
  2. If an 8 or an 11 are rolled it outputs “You rolled an” followed by the result of the roll.
  3. If any other number is rolled it outputs “You rolled a” followed by the result of the roll.

Typical inputs and outputs from the program would be:

Roll a D6

You rolled a 3

Roll a D8

You rolled an 8

Roll a D10

You rolled a 4

Roll a D12

You rolled an 11


Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.


Run your code several times to check that your program has met the success criteria.

Craig'n'Dave logo

Craig ‘n’ Dave

Bett Awards 2024 Finalist