Lesson 4: Operators and selection
Year 7 – Programming essentials in Scratch: part I
What will the program output? (think, write, pair, share)
Starter activity
Pretend that you run this program four times. Each time you type in one of the values below.
What would the program say if the ‘year_group’ variable was set to the following values?
2
Lesson 4: Operators
Objectives
In this lesson, you will:
3
Operators
Activity 1
Last lesson you used a comparison operator in your program.
Can you spot where in this code?
This condition compares the value of ‘health’ to ‘yes’ and checks to see if they match.
4
Comparison operators
Activity 1
Comparison operators compare the values of expressions.
What are each of these conditions checking?
That variable1 is equal to variable2
That variable1 is greater than 10
That 200 is less than variable1
5
Logic operators
Activity 1
Logic operators perform ‘logical operations’.
What are each of these conditions checking?
That ‘number’ is greater than 30 and ‘city’ is equal to Athens (when both are true)
That ‘number’ is greater than 30 or ‘city’ is equal to Athens (when either are true)
That ‘age is greater than 18’ is not true (i.e. it is false)
6
Playing cards: true or false?
Activity 2
You will now be given a playing card.
You will need to know the following of the card’s properties:
Ace is low (value = 1)
7
Playing cards: true or false
Activity 2
You will now be shown expressions.
You have to decide if you card evaluates as true or false.
Stand in the appropriate place in the room, depending on how you have evaluated (true or false).
8
Expression 1
Activity 2
value > 6
9
Expression 2
Activity 2
value = king
and
suit = hearts
10
Expression 3
Activity 2
suit = spades
or
suit = diamond
11
Expression 4
Activity 2
not colour = red
12
Expression 5
Activity 2
value = queen or value = 9
and
colour = black
13
Expression 6
Activity 2
value < 5 or value > 10
and
suit = clubs or suit = hearts
14
The big quiz
Activity 3
This is a game that currently asks geography questions.
Let’s look at how it works.
Together we’ll build a subroutine.
Listen and watch carefully. Once the demonstration is over, you will need to build the same subroutine independently.
15
Being an independent problem-solver
Activity 4
When working on solving coding problems, there may be times where you feel stuck.
Here is what you can do:
Only when you have taken these three steps should you ask your teacher
16
Adding more functionality to the ‘Brain game’
Activity 5
Open ‘The Big Quiz’ worksheet
Work through the tasks to add more functionality to the program
Work independently
You have 20 minutes
17
Plenary: True or false?
Plenary
Complete the plenary worksheet by evaluating each statement and decide if it evaluates to true or false.
18
True or false: Plenary answers
Plenary
19
Statement | Evaluates to true or false? |
7 > 6 | True |
9 = 9 | True |
10 < 9 | False |
(30 < 50) or (30 > 50) | True |
(20 = 20) and (15 < 15) | False |
not (20 = 20) | False |
Next lesson
Summary
In this lesson, you...
Identified the difference between logic and comparison operators
Identified where selection statements can be used and modified our ‘Brain game’ program to include comparison and logical operators
Next lesson, you will…
Learn about count-controlled iteration (loops)
20