Polyhedral dice

Polyhedral dice

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

Try


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:

Investigate


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

Item question

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

REVEAL ANSWER

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.

REVEAL ANSWER

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.

Make


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

Knowledge Organiser

Use these resources to learn about new commands for this level and to help you meet the success criteria.

Notes:

import random

Includes functions from the library called random in your program. 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.


Computers cannot generate random numbers because they can only perform calculations. Instead, they use a calculation on a number known as a `seed` to generate what looks like a random number to the user.


random.seed(x)

Sets the seed x to be used by the random number algorithm. The value of x can be ommitted 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.

Evaluate


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

Craig'n'Dave logo

Craig ‘n’ Dave

In partnership with

Mission Encodeable
Bett Awards 2024 Finalist