Arithmetic Operations
beginner20 minLearning objectives
- Apply arithmetic operators correctly
- Distinguish between floating-point and integer division
- Explain modulus, exponentiation, rounding and truncation
- Develop algorithms that perform mathematical calculations
Learn
AQA 4.1.1.3 — Arithmetic operations
Retrieval: you've already used variables and constants to store numeric values (the previous lesson's price, total) - this lesson is about the operators you use to actually combine and transform those values.
| Operation | Python | Example | Result |
|---|---|---|---|
| Addition | + | 5 + 2 | 7 |
| Subtraction | - | 5 - 2 | 3 |
| Multiplication | * | 5 * 2 | 10 |
| Floating-point division | / | 5 / 2 | 2.5 |
| Integer (floor) division | // | 5 // 2 | 2 |
| Modulus (remainder) | % | 5 % 2 | 1 |
| Exponentiation | ** | 5 ** 2 | 25 |
Integer division vs floating-point division
This is the operator students most often mix up. / always gives a float, even when the numbers divide evenly (10 / 2 is 5.0, not 5). // discards the remainder entirely: 7 // 2 is 3, not 3.5.
Modulus — more useful than it looks
% gives you the remainder, which is exactly what you need to check divisibility:
if number % 2 == 0:
print("Even")
else:
print("Odd")
Rounding vs truncation
round(3.7) gives 4 (rounds to the nearest whole number). int(3.7) gives 3 (truncates — simply discards everything after the decimal point, it does not round). These behave differently for negative numbers too: int(-3.7) is -3, not -4.
Worked example — a simple calculator
a = float(input("First number: "))
b = float(input("Second number: "))
print(f"Sum: {a + b}")
print(f"Difference: {a - b}")
print(f"Product: {a * b}")
print(f"Quotient: {a / b}")
Challenge
Extend the calculator to also print a // b, a % b and a ** b, and explain in a sentence what each one calculates.