Year 7 · Spring 2

Scratch I: Programming essentials · Lesson 2 of 5

Variables: score and lives

PracticalTopic 13 Programming basics

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

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.

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Success criteria

You have got it when you can say:

  • 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.

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Retrieval starter

Questions from before. Write your answers, then show them.

  1. Last lesson

    An 'if… else…' is…

    A SelectionB IterationC Sequence

    A. Selection

  2. Last unit

    Which field makes a good primary key?

    A HouseB StudentIDC FirstName

    B. StudentID

  3. Earlier this year

    Caesar shift 1: 'CAT' becomes…

    A BZSB CAT1C DBU

    C. DBU

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Key words (1 of 2)

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".

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Key words (2 of 2)

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 · step 1 of 1 · part 1 of 2

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.

The explanation · step 1 of 1 · part 2 of 2

Variables: labelled boxes (continued)

!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.

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Try it: Watch the variable boxes

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Quick quiz · 1 of 3

Which loop always runs at least once?

  1. A WHILE … ENDWHILE
  2. B REPEAT … UNTIL
  3. C FOR i ← 1 TO 0

B. REPEAT … UNTIL

REPEAT … UNTIL checks its condition at the end, after the first run.

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Quick quiz · 2 of 3

x ← 4, then x ← x × 2, then x ← x + 1. What is x?

  1. A 8
  2. B 12
  3. C 9

C. 9

4 × 2 = 8, then 8 + 1 = 9. Each line replaces the old value.

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Quick quiz · 3 of 3

Which shape is used for OUTPUT total?

  1. A Diamond
  2. B Parallelogram
  3. C Rectangle

B. Parallelogram

Input and output are always parallelograms.

Year 7 · Scratch I: Programming essentials · Lesson 2 of 5

Exit ticket

Answer on paper before you go. Then check.

  1. What does print("3" + "4") show?

    A An errorB 34C 7

    B. 34 They're strings, so + joins them: 34.

  2. What does 17 % 5 give?

    A 2B 3.4C 3

    A. 2 17 ÷ 5 = 3 remainder 2. % gives the remainder.