1 of 17

Lesson 2: Variables

Year 7 – Programming essentials in Scratch: part I

2 of 17

Lesson 2 : Variables

Objectives

In this lesson, you will:

  • Define what a variable is
  • Recognise that computers follow the control flow of input/process/output
  • Predict the outcome of a simple sequence that includes variables
  • Trace the values of variables within a sequence
  • Make a sequence that includes a variable

2

3 of 17

Input — process — output

Activity 1

3

INPUT

OUTPUT

PROCESS

STORAGE

4 of 17

Meet Big Ed

Activity 2

Big Ed is your friendly chatbot.

Your task is to work in pairs to answer the questions on the activity sheet. You’ll find out what the code does and have the chance to experiment with it.

Start by opening the Scratch program.

ncce.io/biged1

4

5 of 17

PREDICT

Activity 2

With a partner, spend time reading the code on the right. Predict what you think will happen.

Run the Scratch code from the link provided.

  • Were your predictions correct?
  • Did anything surprise you about the code?
  • Did you miss anything out?

5

6 of 17

Worksheet: INVESTIGATE and MODIFY

Activity 2

Continue with the worksheet.

Work in pairs, but complete your own worksheet.

Follow the instructions and investigate how the code works.

Move through the tasks independently.

Don’t wait for your teacher to instruct you to move to the next section.

6

7 of 17

INVESTIGATE: Answers

Activity 2

How do the following two blocks relate to each other?

7

When your program reaches the ask_name block, it calls the subroutine ‘define ask_name’.

‘define ask_name’ is a subroutine.

8 of 17

INVESTIGATE: Answers

Activity 2

What has this changed about the program when you run it?

Why do you think this is?

8

Big Ed will now only say “Hello”.

As the question has not been asked, there is no ‘answer’.

The line ‘set name to answer’ will now give name an empty value.

9 of 17

INVESTIGATE: Answers

Activity 2

Below ‘define ask_name’, there are two variables being used.

What are their names?

9

  1. Answer
  2. Name

10 of 17

INVESTIGATE: Answers

Activity 2

Why do you think it only says “Hello” and not “Hello” and the name you entered?

What can you learn from this?

10

It is because ‘name’ is being linked to ‘answer’ before the question is asked.

You must always set the value of a variable before using it.

11 of 17

Trace the score variable: What will Big Ed say?

Plenary

Big Ed has just arrived on a new planet and he’s measuring the temperature of his new environment.

Use the activity sheet to trace (keep track of) the value of the temperature variable on each line that it is referenced.

Fill in your activity sheet and write down what Ed will say on each line.

11

12 of 17

Trace the score variable: What will Big Ed say?

Plenary

12

13 of 17

Trace the score variable: What will Big Ed say?

Plenary

13

14 of 17

Trace the score variable: What will Big Ed say?

Plenary

14

15 of 17

Trace the score variable: What will Big Ed say?

Plenary

15

16 of 17

Trace the score variable: What will Big Ed say?

Plenary

16

17 of 17

Next lesson

Summary

In this lesson, you…

  • Defined a variable
  • Recognised that computers follow the control flow of input/process/output
  • Predicted the outcome of a simple sequence that includes variables
  • Traced a variable within a sequence

Next lesson, you will…

Learn about how to control the flow of a sequence using selection

17