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

Preview

AC 2.3: Making decisions with IF, AND, OR and 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.

60 minutes

Short, medium or long?

A reading club lists the pages in each book. The leader wants a label next to every book: short, medium or long. Another column should say who may borrow.

Typing 200 labels is slow. A decision written once can fill the whole column.

Key words

WordWhat it means
Conditiona test that is true or false
IFpicks one answer when a condition is true and another when it is false
ANDtrue only when both conditions are true
ORtrue when at least one condition is true
NOTturns true into false and false into true
Nested IFan IF placed inside another IF, to choose between three or more answers
Formulaa calculation typed into a cell, starting with =

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

By the end of this lesson

Note

I can use IF, AND, OR and NOT, alone and together, to label values and to test them.

Starter

Have a go

Starter

3 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.

No spreadsheet here

Important

This platform has no spreadsheet program. Here the cells are a table and the formula is shown as text. You do the same job with code. On site you use a real spreadsheet program.

The reading club as cells

RowA nameB yearC pagesD fines (pence)
1Amy8900
2Bo725050
3Cy94000
4Di61200

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

Four decisions, as formulas

FormulaSaysAnswer for row 2 (Bo)
`=IF(C2<100,"short","not short")`Label a book by one testnot short
`=IF(AND(B2>=7,D2=0),"yes","no")`Both tests must passno (Bo has a fine)
`=IF(OR(C2<100,C2>300),"odd","normal")`Either test may passnormal
`=IF(NOT(D2=0),"owes","clear")`Turn a test roundowes

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

Try it: the same decision in SQL

Code: sql
SELECT name, pages,
  CASE WHEN pages < 100 THEN 'short'
       WHEN pages < 300 THEN 'medium'
       ELSE 'long' END AS band
FROM readers;

-- AND, OR and NOT work inside WHERE.
SELECT name FROM readers WHERE year >= 7 AND fines_pence = 0;

Three answers need a nested IF

One IF gives two answers. For three, put a second IF in the "false" part: =IF(C2<100,"short",IF(C2<300,"medium","long")).

It reads top down. The first true test wins, so put the tests in the right order.

The lesson goes on

5 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.