1 of 20

Lesson 4: Operators and selection

Year 7 – Programming essentials in Scratch: part I

2 of 20

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

3 of 20

Lesson 4: Operators

Objectives

In this lesson, you will:

  • Create conditions that use comparison operators (>,<,=)
  • Create conditions that use logic operators (and/or/not)
  • Identify where selection statements — that include comparison and logical operators — can be used in a program

3

4 of 20

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

5 of 20

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

6 of 20

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

7 of 20

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:

  • Colour
  • Suit
  • The value (number or jack, queen, king, ace, joker)

Ace is low (value = 1)

7

8 of 20

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

9 of 20

Expression 1

Activity 2

value > 6

9

10 of 20

Expression 2

Activity 2

value = king

and

suit = hearts

10

11 of 20

Expression 3

Activity 2

suit = spades

or

suit = diamond

11

12 of 20

Expression 4

Activity 2

not colour = red

12

13 of 20

Expression 5

Activity 2

value = queen or value = 9

and

colour = black

13

14 of 20

Expression 6

Activity 2

value < 5 or value > 10

and

suit = clubs or suit = hearts

14

15 of 20

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

16 of 20

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:

  1. Carefully read over the instructions again. Stop and think through the problem.
  2. Read the support tips and look at your work from previous lessons/tasks
  3. Ask your classmate to prompt you (not do it for you)

Only when you have taken these three steps should you ask your teacher

16

17 of 20

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

18 of 20

Plenary: True or false?

Plenary

Complete the plenary worksheet by evaluating each statement and decide if it evaluates to true or false.

18

19 of 20

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

20 of 20

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