Skip to the page
Year 7 · Spring 2 · Scratch I: Programming essentials

Variables: score and lives

PracticalPresent ▶

What this lesson covers

Topic 13 Programming basics

KS3 Computing · A program stores information in variables, works on it with operators, and controls the order with sequence, selection and iteration. Examples are in Python, with Scratch alongside for Year 7.

ProgrammingCambridge Lower Secondary Computing 0860

You will learn to

  • Explain what a variable is: a named box that holds one value at a time.
  • Create a score variable that goes up by 1 each time the sprite is clicked.
  • Use a lives variable that starts at 3 and counts down.

Success criteria

  • I can make a variable and show it on the stage.
  • I can set the score to 0 when the green flag is clicked.
  • I can make lives go down by 1 and say the value after each change.

Key words

Say each word, then read what it means. Every one is in the glossary too.

variable
A named place in memory that holds a value.
assignment
Storing a value in a variable. = in Python, ← in pseudocode.
Casting
Changing a value from one data type to another, like int("13").
Concatenation
Joining strings together: "7" + "7" = "77".
Selection
Choosing a path with if / else.
Iteration
Repeating steps: a loop.
Boolean
A value that is only True or False.
Infinite loop
A loop whose condition never becomes false.

The explanation

Read it here, or open the study page below to go one step at a time with things to try.

Variables: labelled boxes

A variable is a named box in memory that holds a value.

score = 0
score = score + 10
print(score)
  1. score = 0: make a box called score, put 0 in it. This is assignment.
  2. score = score + 10: read the right side first. 0 + 10 = 10. Put 10 back in the box.
  3. print(score) shows 10.
!Watch out

In code, = means 'store', not 'equals'. To ask if two things are equal, use ==.

e.g.Example

Scratch: the orange 'set score to 0' and 'change score by 10' blocks.

Study it

Open the study page and go one step at a time.

The steps for this lesson

Try it

Check yourself

One question at a time. The reason shows after each answer.

Saved on this device.