Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Comparing and combining with and, or, not

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

The person at the cinema door

A worker at the cinema door checks you. Are you 15 or older? Do you have a ticket? You can go in only if both answers are yes.

Each question has a yes or no answer: True or False. A program asks the same questions with two kinds of operator. An operator is a symbol or word that does something to values.

Key words

WordWhat it meansExample
Relational operatorAn operator that compares two values and gives True or False.age >= 15
BooleanA value that is True or False.True
Boolean operatorAn operator that joins True and False values: and, or, not.a and b
OperatorA symbol or word that does something to values.>
Truth tableA table that shows the result of a Boolean operator for every case.True and False is False
ConditionA question that gives True or False.score > 10

The cells students fill in are left blank in this preview.

Try it: compare

Code: python
age = 16

print(age == 16)
print(age < 16)
print(age >= 16)
print(age != 20)

# Each line asks a question. The answer is True or False.
# Change age to 15 and run again.

The six relational operators

OperatorMeansExampleResult when age is 16
`==`Is equal to`age == 16`True
`!=`Is not equal to`age != 16`False
`<`Is less than`age < 16`False
`>`Is greater than`age > 16`False
`<=`Is less than or equal to`age <= 16`True
`>=`Is greater than or equal to`age >= 16`True

The cells students fill in are left blank in this preview.

One equals or two?

data-callouts.warning.label

One = puts a value into a name. Two == asks a question: are these equal? Writing if age = 16 is a mistake. Write if age == 16.

True or False?

Have a go

True or False?

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Join questions with and, or, not

and needs both sides to be True. or needs at least one side to be True. not turns True into False and False into True.

A truth table shows every case.

Truth table for and, or

ABA and BA or B
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse

The cells students fill in are left blank in this preview.

Truth table for not

Anot A
TrueFalse
FalseTrue

The cells students fill in are left blank in this preview.

The lesson goes on

9 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.