You are on page 1of 2

Lesson 8 Dice Game

LO: To understand how to create a dice game

By the end of this lesson you should be able to:

 All should know how to get a total from a set of dice throws
 Some of you will be able to create totals 2 players
 Few of you will be able to compare totals

Homework
Revision for end of unit test: E-Safety – Scratch – Python

Go to…>> CHSA website >> Students >> Computer Science Resources >> Login >>
Year 8 Revision

Use PowerPoint on SharePoint

Starter
Study the code below and identify (through annotation)

1. The tab indent spaces required.


2. The different conditions
3. The different statements
Year 8: Python Programming HA
V1 20-21

Activity 1 Computer Total


We will be creating a dice game. It will have two players: Computer (player 1)
and user (player2).
Each player will throw two dices. The two numbers will be added together and
the player with the highest total wins.

1. Type up the code below and run it by pressing F5.


This will generate the first number and display the result to the screen.

2. Make the computer (player 1) have a second number and display the
result to the screen. Use the variable name computernumber2.
NOTE: Only use import random once. This ideally placed on the first line.
It does not need to be used again for the second or any subsequent
random numbers
3. Write a line of code that will now display the total of the two throws.
Add the variables (computernumber and computernumber2) together and
save the total in the TotalComp variable.

Activity 2 User Total


1. Create 2 more random numbers for the user (player 2).
Hint: It is the same approach to activity 1
Use the following variable names
Usernumber1 – Dice 1
Usernumber2 – Dice 2
UserTotal – Total of both throw

2. Print screen your code and print it out as evidence of your work. Add
your name and form to the document first.

Activity 2 Winner Total


1. Use the if() else statement to compare the two totals.
2. The total which is greater will displayed as the winner.
3. Congratulate the winner and write a sympathy message for the loser
4. Print screen your code and print it out as evidence of your work. Add
your name and form to the document first.

Page 1 of 2

You might also like