Home / GCSE · Edexcel / Computer Science / Computational thinking

CPX2Operators and Truth Tables

Edexcel 1CP2 · 1.2.3

Arithmetic operators

Arithmetic operators do calculations. These are the seven you need, with Python’s symbols.

  • / always gives a real (decimal) result, even when it divides exactly: 8 / 2 is 4.0.
  • // gives the whole-number part only; % gives what is left over.
  • ** raises to a power: 2 ** 10 is 1024.
OperationPythonExampleResult
Addition+7 + 29
Subtraction-7 - 25
Multiplication*7 * 214
Division/7 / 23.5
Integer division//7 // 23
Modulus (remainder)%7 % 21
Exponentiation (power)**7 ** 249

Three families of operators, and what each gives back

Exam tipLearn the symbols both ways round. Pearson asks for the result of an expression such as 5 // 2 (answer 2), and offers wrong answers that are the results of the other operators (2.5, 1, 0.5).
Integer division
Division that gives only the whole-number part of the answer: 7 // 2 = 3.
Modulus
The remainder after integer division: 7 % 2 = 1.
Exponentiation
Raising a number to a power: 7 ** 2 = 49.
Edexcel 1CP2 · 1.2.3

When to use /, // and %

Choose the operator that matches the question being asked.

  • / when you need the exact answer, e.g. the mean of some scores.
  • // when you need how many whole groups fit, e.g. full boxes, complete weeks, full teams.
  • % when you need what is left over, e.g. eggs that don’t fill a box.
  • Even or odd: number % 2 == 0 is True for even numbers.
  • Is it a multiple? n % 5 == 0 is True when n is a multiple of 5.
Worked exampleA bakery packs 50 rolls into bags of 6. How many full bags are there, and how many rolls are left over?
  1. 50 // 6 = 88 × 6 = 48, so 8 bags are full
  2. 50 % 6 = 250 − 48 = 2 rolls left over
  3. 50 / 6 = 8.333…no good here: you can’t sell a third of a bag
8 full bags and 2 rolls left over.
Exam tip% gives the remainder, not the decimal part. 17 % 5 is 2, not 0.4.
Edexcel 1CP2 · 1.2.3

Order of operations (BIDMAS)

Python works out arithmetic in the same order as maths: Brackets, Indices, Division and Multiplication, Addition and Subtraction.

  • Indices means powers: **.
  • *, /, // and % are on the same level: work left to right.
  • + and - are on the same level: work left to right.
  • Use brackets to make the order you want clear, even when they aren’t strictly needed.
Worked exampleWork out 4 + 6 * 2 ** 2.
  1. 2 ** 2 = 4indices first
  2. 6 * 4 = 24then multiplication
  3. 4 + 24 = 28addition last
28. With brackets, (4 + 6) * 2 ** 2 would be 40.
Worked exampleWork out 3 + 5 % 3 and (3 + 5) % 3.
  1. 5 % 3 = 2, then 3 + 2 = 5% is done before +
  2. 3 + 5 = 8, then 8 % 3 = 2the brackets come first
5 and 2.
Watch out20 - 8 / 4 is 18.0, not 3: the division happens first, and / makes the answer a real.
Edexcel 1CP2 · 1.2.3

Relational operators

Relational operators compare two values. The result is always True or False.

  • = on its own is assignment (store a value). == asks a question (are they equal?).
  • Comparing strings is case-sensitive: "cat" == "Cat" is False.
  • Relational tests are used in if and while conditions.
MeaningPythonExampleResult
Equal to==5 == 5True
Not equal to!=5 != 5False
Less than<3 < 3False
Less than or equal to<=3 <= 3True
Greater than>10 > 9True
Greater than or equal to>=10 >= 10True
Exam tipWhen asked for the possible results of a relational test, write True and False. Pearson’s mark scheme does not accept 1/0 or yes/no for this.
Relational operator
An operator that compares two values and gives True or False: ==, !=, <, <=, >, >=.
Edexcel 1CP2 · 1.2.3

Logical operators: AND, OR, NOT

Logical (Boolean) operators combine or reverse True/False values. The result is True or False.

  • AND: True only when both sides are True.
  • OR: True when at least one side is True.
  • NOT: reverses a single value. NOT True is False.
  • In Python they are written and, or, not. Pearson puts each condition in brackets: if ((age >= 12) and (age <= 16)):.
Worked exampleage = 15 and member = False. Evaluate each condition.
  1. (age >= 12) and (age <= 16)True and True → True
  2. (age < 12) or memberFalse or False → False
  3. not membernot False → True
True, False, True.
Watch outEach side of and or or must be a full condition. age >= 12 and <= 16 is not valid Python.
Logical operator
An operator that combines or reverses True/False values: AND, OR, NOT.
Edexcel 1CP2 · 1.3.1

Truth tables for AND, OR and NOT

A truth table shows the output for every possible combination of inputs. Use 1 for True and 0 for False.

  • n inputs give 2ⁿ rows: 2 inputs → 4 rows, 3 inputs → 8 rows.
  • List the inputs in binary counting order: 00, 01, 10, 11 for two inputs; 000 up to 111 for three.
  • AND with three inputs is 1 in only one row (all 1s). OR with three inputs is 0 in only one row (all 0s).
ABA AND BA OR B
0000
0101
1001
1111
ANOT A
01
10

Listing three inputs in binary counting order, so no combination is missed or repeated

Exam tipFill truth tables with 1 and 0 (or T and F). In 2023 many students used ticks and crosses and lost marks.
Not needed for EdexcelEdexcel uses only AND, OR and NOT, in truth tables and written expressions. You don’t need to draw circuit diagrams: if a video shows them, skip that part.
Truth table
A table showing the output of a logical expression for every possible combination of inputs.
Edexcel 1CP2 · 1.3.1

Order of precedence: brackets, NOT, AND, OR

When an expression mixes operators, work them out in this order: brackets, then NOT, then AND, then OR.

  • NOT applies only to the value straight after it, unless brackets say otherwise.
  • NOT A AND B means (NOT A) AND B, not NOT (A AND B).
  • A OR B AND C means A OR (B AND C), because AND comes before OR.
  • Python follows the same order: not, then and, then or.

Precedence for logical operators

Worked exampleA = 0 and B = 0. Compare NOT A AND B with NOT (A AND B).
  1. NOT A AND B = (NOT 0) AND 0 = 1 AND 0 = 0NOT first, then AND
  2. NOT (A AND B) = NOT (0 AND 0) = NOT 0 = 1brackets first, then NOT
The results differ (0 and 1), so the brackets matter.
Exam tipIf you write an expression, add brackets to show what you mean. (A OR B) AND NOT C can’t be misread.
Edexcel 1CP2 · 1.3.1

Building a truth table with working columns

For a longer expression, add an intermediate column for each part, then combine them. It is much harder to go wrong.

  • Working backwards: if a question gives a column of values and asks for its expression, compare it with the input columns. A column that is 1 only when both A and C are 1 is A AND C.
  • To write an expression from a finished table, look at the rows where the output is 1 and ask what they have in common.
Worked exampleComplete a truth table for X = A AND NOT (B OR C).
  1. List A, B, C from 000 to 1113 inputs, so 8 rows
  2. Column B OR C: 0, 1, 1, 1, 0, 1, 1, 1brackets first
  3. Column NOT (B OR C): 1, 0, 0, 0, 1, 0, 0, 0then NOT
  4. Column X = A AND that: 0, 0, 0, 0, 1, 0, 0, 0AND last: only row 100 has both 1
ABCB OR CNOT (B OR C)X
000010
001100
010100
011100
100011
101100
110100
111100
Exam tipIn 2025 many students could fill in values but couldn’t name the expression for a working column. Practise both directions.
Edexcel 1CP2 · 1.3.1

Writing expressions for real situations

Pearson gives a situation in words. Turn each condition into a letter, then link them with AND, OR and NOT.

  • “and”, “both”, “as well as” → AND.
  • “or”, “either”, “at least one” → OR.
  • “not”, “unless”, “is off”, “isn’t” → NOT.
  • “either … or …, and also …” needs brackets round the OR part.
Worked exampleA drinks machine gives a drink (G) when a coin has been inserted (C) and a button is pressed (B), unless the machine is empty (E). Write the expression.
  1. coin AND buttonboth are needed
  2. “unless it is empty” → NOT Ethe drink comes only when E is 0
  3. G = C AND B AND NOT Eall three conditions must hold
G = C AND B AND NOT E. Check one row: C = 1, B = 1, E = 1 gives 1 AND 1 AND 0 = 0, so an empty machine gives no drink.
Exam tipCheck your expression against the story: pick a row of inputs, work out the output, and make sure the output matches what should happen.