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.
Arithmetic operators (spec 7.1.3)
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | add | 7 + 2 | 9 |
| - | subtract | 7 - 2 | 5 |
| * | multiply | 7 * 2 | 14 |
| / | divide (always a float) | 7 / 2 | 3.5 |
| // | integer division (floor) | 7 // 2 | 3 |
| % | modulus (remainder) | 7 % 2 | 1 |
| two asterisks | exponent (power) | 7 to the power 2 | 49 |
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 1Note: // 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
TrueWorked example
Use // and % to convert 200 minutes into hours and minutes.
- hours = 200 // 60 = 3
- minutes = 200 % 60 = 20
Answer: 3 h 20 min
Check yourself
- What is displayed when this code runs?
```python
print(47 % 5)
```
Show answer
2. 47 = 9 x 5 + 2, so the remainder is 2.
- What is displayed when this code runs?
```python
print(47 // 5)
```
Show answer
9. 5 goes into 47 nine whole times: 9.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Computer Science specification (XCP01/YCP01), first teaching 2026
- Pearson IAL Computer Science Unit 2 Programming Language Subset (PLS), Python 3
- Pearson IAL Computer Science IAS sample assessment materials (Unit 2 paper and mark scheme)
Last updated 8 November 2026. Spotted a mistake? Tell us.