Lesson 2: Variables
Year 7 – Programming essentials in Scratch: part I
Lesson 2 : Variables
Objectives
In this lesson, you will:
2
Input — process — output
Activity 1
3
INPUT
OUTPUT
PROCESS
STORAGE
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.
4
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.
5
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
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.
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.
INVESTIGATE: Answers
Activity 2
Below ‘define ask_name’, there are two variables being used.
What are their names?
9
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.
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
Trace the score variable: What will Big Ed say?
Plenary
12
Trace the score variable: What will Big Ed say?
Plenary
13
Trace the score variable: What will Big Ed say?
Plenary
14
Trace the score variable: What will Big Ed say?
Plenary
15
Trace the score variable: What will Big Ed say?
Plenary
16
Next lesson
Summary
In this lesson, you…
Next lesson, you will…
Learn about how to control the flow of a sequence using selection
17