All subjects · Computer Science · WCP02 Practical Programming and Problem-solving

Arithmetic, relational and Boolean operators

Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving

Operators combine values. You need to know exactly what each one returns, especially integer division and modulus.

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

Arithmetic operators (spec 7.1.3)

OperatorMeaningExampleResult
+add7 + 29
-subtract7 - 25
*multiply7 * 214
/divide (always a float)7 / 23.5
//integer division (floor)7 // 23
%modulus (remainder)7 % 21
two asterisksexponent (power)7 to the power 249

Precedence

Brackets first, then the power operator, then * / // %, then + and -. Operators of equal precedence work left to right. Use brackets to make your intention clear.

print(2 + 3 * 4)
print((2 + 3) * 4)
print(20 - 6 // 4 * 2)
print(-7 // 2, -7 % 2)

Output:

14
20
18
-4 1

Note: // rounds down (towards minus infinity), so -7 // 2 is -4, not -3.

Relational operators

== (equal to), != (not equal to), <, <=, >, >=. They return True or False. Do not confuse == (comparison) with = (assignment). Strings compare by character codes, so "Zebra" < "apple" is True because capital letters have smaller codes.

Boolean operators

and is True only if both sides are True; or is True if at least one side is True; not reverses a value. Precedence: not, then and, then or.

age = 16
has_ticket = True
print(age >= 18 or has_ticket)
print(age >= 18 and has_ticket)
print(not has_ticket)
print(True or False and False)

Output:

True
False
False
True

Worked example

Use // and % to convert 200 minutes into hours and minutes.

  1. hours = 200 // 60 = 3
  2. minutes = 200 % 60 = 20

Answer: 3 h 20 min

Key idea: / always gives a float; // gives the whole-number quotient rounded down; % gives the remainder; and/or/not combine conditions with not before and before or.

Check yourself

  1. What is displayed when this code runs? ```python print(47 % 5) ```
    Show answer

    2. 47 = 9 x 5 + 2, so the remainder is 2.

  2. What is displayed when this code runs? ```python print(47 // 5) ```
    Show answer

    9. 5 goes into 47 nine whole times: 9.

  3. Which of these is displayed when this code runs? ```python print(12 / 4) ```
    • 3
    • 3.0
    • 3.00
    • 0
    Show answer

    3.0. / always returns a float, so the result is 3.0, not 3.

  4. What is displayed when this code runs? ```python print(3 + 4 * 2 ** 2) ```
    Show answer

    19. The power is first (2 squared = 4), then 4 * 4 = 16, then 3 + 16 = 19.

  5. What is displayed when this code runs? ```python print(-17 // 5) ```
    Show answer

    -4. -17 / 5 = -3.4, and // rounds down towards minus infinity, giving -4.

  6. What is displayed when this code runs? ```python x = 7 print(x > 5 and x % 2 == 0) ```
    • True
    • 7
    • False
    • Error
    Show answer

    False. x > 5 is True but 7 % 2 == 0 is False; and needs both, so False.

  7. What is displayed when this code runs? ```python a = True b = False c = False print(a or b and c) ```
    • True
    • False
    • None
    • a
    Show answer

    True. and is evaluated first: b and c is False; then a or False is True.

  8. This should print 'valid' only when n is between 1 and 10 inclusive, testing n = 0, 1, 10 and 11. Which line completes it? ```python for n in [0, 1, 10, 11]: __________ print("valid", end=" ") else: print("invalid", end=" ") ```
    • `if n >= 1 or n <= 10:`
    • `if n >= 1 and n <= 10:`
    • `if n > 1 and n < 10:`
    • `if not n >= 1:`
    Show answer

    `if n >= 1 and n <= 10:`. Both limits must hold, so use and with inclusive comparisons: 0 and 11 are invalid, 1 and 10 are valid.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.