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:
Questions to think about with this program to check your understanding:
Identify two constants in the program that could be variables instead.
State what the two parameters are used for in the randint command in line 13.
Change the program so that it:
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 these resources to learn about new commands for this level and to help you meet the success criteria.
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.
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.
Generates a random number between x and y inclusive.
Run the code several times to check that your program has met the success criteria.