🎯 Syllabus & Goals 3 min
Cambridge 8.1.4 · Arithmetic, logical and Boolean operators Paper 2 · Algorithms, Programming and Logic
By the end of this lesson you can:
- Evaluate expressions using
+ - * / ^,MODandDIV, with brackets, and write them in Python. - Use the logical (comparison) operators
= <> < > <= >=and know their Python forms. - Combine conditions with the Boolean operators
AND,ORandNOT, and predict the result.
Textbook: Chapter 8, §8.1.4(f) (pp. 317–318); MOD and DIV also §8.1.7 (pp. 327–328)
Recap / Warm-Up 5 min
Last lesson: totals, counts and strings. Every one of them relied on an operator — + to total, = to compare a character, & to join strings.
Quick starter
29 students are put into teams of 4. How many full teams are there, and how many students are left over?
Reveal the answer
7 full teams (4 × 7 = 28) with 1 student left over. You just did DIV (7) and MOD (1) in your head.
🧠 Key Concept 14 min
Total / Count >= 50 AND NOT Absent uses all three families at once.1 · Arithmetic operators
| Pseudocode | Action | Python | Example → result |
|---|---|---|---|
+ - * | Add, subtract, multiply | + - * | 17 * 5 → 85 |
/ | Divide (result is REAL) | / | 17 / 5 → 3.4 |
^ | Raise to the power of | ** | 2 ^ 3 → 8 |
MOD(17, 5) | Remainder of a division | 17 % 5 | 2 |
DIV(17, 5) | Whole-number part (quotient) of a division | 17 // 5 | 3 |
DIV counts the full groups; MOD counts what is left over.DIV(135, 60) = 2 and MOD(135, 60) = 15. A spreadsheet shades every other row by testing MOD(RowNumber, 2) = 0— that is how any program tests for an even number.2 · Logical operators
Logical operators compare two values. The result is always TRUE or FALSE, so they are used to decide the path through a program.
| Pseudocode | Meaning | Python |
|---|---|---|
> / < | Greater than / less than | > / < |
>= / <= | Greater than or equal / less than or equal | >= / <= |
= | Equal | == |
<> | Not equal | != |
3 · Boolean operators
Boolean operators join comparisons into one more complex condition.
AND needs both sides TRUE; OR needs at least one; NOT flips the value. Python writes them and, or, not.Worked Example 12 min
Example 1 · Arithmetic — evaluating expressions and splitting teams
First, evaluate each expression by hand, then check with Python.
print(17 + 5, 17 - 5, 17 * 5) print(17 / 5) # divide: always gives a REAL (float) print(2 ** 3) # power (^ in pseudocode) print(17 % 5) # MOD: remainder print(17 // 5) # DIV: whole-number part print(3 + 4 * 2) # * before + print((3 + 4) * 2) # brackets first
22 12 85 3.4 8 2 3 11 14
Now a real task: a teacher splits a class into teams of a chosen size. Output the number of full teams and how many students are left over.
Cambridge pseudocode
DECLARE Students, TeamSize : INTEGER
DECLARE Teams, LeftOver : INTEGER
OUTPUT "Number of students: "
INPUT Students
OUTPUT "Students per team: "
INPUT TeamSize
Teams ← DIV(Students, TeamSize)
LeftOver ← MOD(Students, TeamSize)
OUTPUT "Full teams: ", Teams
OUTPUT "Students left over: ", LeftOver
IF LeftOver = 0
THEN
OUTPUT "Everyone is in a full team"
ENDIFThe same in Python
# Split a class into teams students = int(input("Number of students: ")) team_size = int(input("Students per team: ")) teams = students // team_size # DIV left_over = students % team_size # MOD print("Full teams:", teams) print("Students left over:", left_over) if left_over == 0: print("Everyone is in a full team")
Number of students: 29 Students per team: 4 Full teams: 7 Students left over: 1 Number of students: 24 Students per team: 4 Full teams: 6 Students left over: 0 Everyone is in a full team
DIV(29, 4): 4 goes into 29 seven whole times → 7.DIV throws away the remainder.MOD(29, 4): 29 − 7 × 4 = 1 → 1.MOD keeps only the remainder.LeftOver = 0tests for an exact split.MOD(X, Y) = 0means "X divides exactly by Y".
Example 2 · Logical and Boolean — a youth-club entry check
A youth club admits people aged 13 to 17 inclusive who are not banned.
Cambridge pseudocode
DECLARE Age : INTEGER
DECLARE Answer : CHAR
DECLARE Banned : BOOLEAN
OUTPUT "Age: "
INPUT Age
OUTPUT "Banned (Y/N)? "
INPUT Answer
Banned ← Answer = 'Y'
IF Age >= 13 AND Age <= 17 AND NOT Banned
THEN
OUTPUT "Welcome in"
ELSE
OUTPUT "Entry refused"
ENDIFThe same in Python
# Youth club entry: aged 13 to 17 inclusive AND not banned age = int(input("Age: ")) banned = input("Banned (Y/N)? ") == "Y" if age >= 13 and age <= 17 and not banned: print("Welcome in") else: print("Entry refused")
Banned ← Answer = 'Y' stores the result of a comparison — TRUE or FALSE — in a BOOLEAN variable.
| Age | Answer | Age >= 13 | Age <= 17 | NOT Banned | Whole condition | OUTPUT |
|---|---|---|---|---|---|---|
| 15 | N | TRUE | TRUE | TRUE | TRUE | Welcome in |
| 15 | Y | TRUE | TRUE | FALSE | FALSE | Entry refused |
| 18 | N | TRUE | FALSE | TRUE | FALSE | Entry refused |
Output — the three test runs
Age: 15 Banned (Y/N)? N Welcome in Age: 15 Banned (Y/N)? Y Entry refused Age: 18 Banned (Y/N)? N Entry refused
Try It Yourself 12 min
Goal: Without a computer, work out: MOD(23, 6), DIV(23, 6), 2 ^ 5, 10 - 4 / 2, (10 - 4) / 2. Then check them in Python.
Goal: Input two numbers. Output a message saying whether they are equal or not equal, and which is larger. Use <> in pseudocode and != in Python.
Goal: A year is a leap year if it divides exactly by 4 and not by 100 — unless it also divides exactly by 400. Write a program that inputs a year and outputs whether it is a leap year. Test with 2024, 1900 and 2000.
Hint
"Divides exactly by 4" is MOD(Year, 4) = 0. The whole rule fits in one condition: (MOD(Year, 4) = 0 AND MOD(Year, 100) <> 0) OR MOD(Year, 400) = 0. Use brackets to make the grouping clear.
📝 Exam Practice 10 min
State the value of each variable after these statements run.
Value1 ← MOD(20, 6) Value2 ← DIV(20, 6) Value3 ← 4 + 3 ^ 2
Mark scheme
- Value1 = 2 (1)
- Value2 = 3 (1)
- Value3 = 13 (1)
Explain the difference between a logical operator and a Boolean operator. Give an example of each.
Mark scheme
- A logical operator compares two values (1)…
- …e.g.
>,<>,<=(1). - A Boolean operator combines conditions / TRUE–FALSE values into a more complex expression (1)…
- …e.g.
AND,OR,NOT(1).
Write pseudocode that inputs a whole number and outputs "Even" or "Odd", and also outputs "Multiple of 5" if the number divides exactly by 5.
Mark scheme
- Prompt and input of the number (1).
IF MOD(Number, 2) = 0(1).- Correct Even / Odd outputs with ELSE and ENDIF (1).
- Separate
IF MOD(Number, 5) = 0with its output (1).
A student writes IF Mark > 40 AND < 60. Identify the error and write the correct condition.
Mark scheme
- The variable is missing from the second comparison (1).
IF Mark > 40 AND Mark < 60(1).
🗝️ Recap & Key Terms 3 min
Arithmetic operators calculate — remember MOD (remainder) and DIV (whole part). Logical operators compare and give TRUE/FALSE. Boolean operators — AND, OR, NOT — join comparisons. Brackets decide the order.
- Operator
- A special character or word in a programming language that identifies an action to be performed.
- Arithmetic operator
- An operator that is used to perform calculations.
- Logical operator
- An operator used to decide the path through a program by comparing values to give TRUE or FALSE.
- Boolean operator
- An operator (AND, OR, NOT) used with logical operators to form more complex expressions.
- MOD
- Returns the remainder of a division.
- DIV
- Returns the quotient — the whole-number part — of a division.
Homework 1 min
Task (≤ 15 min): Write pseudocode that inputs a number of seconds and outputs it as hours, minutes and seconds (e.g. 3725 → 1 h 2 min 5 s), using only DIV and MOD. [4]
Model answer
DECLARE TotalSeconds, Hours, Minutes, Seconds : INTEGER OUTPUT "Enter a number of seconds: " INPUT TotalSeconds Hours ← DIV(TotalSeconds, 3600) Minutes ← DIV(MOD(TotalSeconds, 3600), 60) Seconds ← MOD(TotalSeconds, 60) OUTPUT Hours, " h ", Minutes, " min ", Seconds, " s"
Marks: input (1); hours with DIV 3600 (1); minutes from the remainder (1); seconds with MOD 60 and output (1). Check: 3725 DIV 3600 = 1; 125 DIV 60 = 2; 3725 MOD 60 = 5.