Arithmetic Operators
Use Python symbols for calculations, including DIV and MOD equivalents.
Arithmetic operators perform calculations. The important part is knowing both the general operator and the Python symbol that performs the same job.
Predict
Read the code first. Do not run it yet.
a = 17
b = 5
print(a // b)
print(a % b)
print(2 ** 4)- Predict all three outputs.
- Which line gives the quotient?
- Which line gives the remainder?
Investigate
Use this code to explain exactly how the program works.
total = 23
boxes = 4
full_boxes = total // boxes
left_over = total % boxes
print(full_boxes, left_over)- What do
full_boxesandleft_overrepresent? - Why is
//more suitable than/for full boxes? - How are
DIVandMODrepresented in Python?
Operator comparison
| Operation | General form | Python | Example |
|---|---|---|---|
| Addition | + | + | 7 + 2 → 9 |
| Subtraction | - | - | 7 - 2 → 5 |
| Multiplication | * | * | 7 * 2 → 14 |
| Division | / | / | 7 / 2 → 3.5 |
| Integer quotient | DIV | // | 7 // 2 → 3 |
| Remainder | MOD | % | 7 % 2 → 1 |
| Exponentiation | ^ | ** | 2 ** 3 → 8 |
^ can mean exponentiation. In Python, exponentiation is **; ^ has a different meaning.A complete calculation
price = 8.50
quantity = 3
total = price * quantity
print(total)25.5
*multiplies the two numeric values.- The result is stored in
totalbefore it is printed.
Self-study guide
Arithmetic operators let programs calculate new numeric values. Most symbols match between OCR Exam Reference Language and Python, but three differences are especially important: OCR DIV becomes Python //, OCR MOD becomes Python %, and OCR exponentiation ^ becomes Python **.
Do not use Python ^ for powers. In Python, ^ is a bitwise XOR operator, so it is not the GCSE exponentiation operator you are trying to express.
OCR Exam Reference Language ↔ Python
| OCR Exam Reference Language / term | Python | What to remember |
|---|---|---|
+ | + | Addition. |
- | - | Subtraction. |
* | * | Multiplication. |
/ | / | Division. |
DIV | // | Whole-number quotient / floor division for the positive GCSE-style examples used here. |
MOD | % | Remainder after division. |
^ | ** | Exponentiation. Python ^ is not exponentiation. |
Worked example
DIV and MOD are easiest to understand as “complete groups” and “left over”.
items = 29
box_size = 6
full_boxes = items // box_size
left_over = items % box_size
print(full_boxes)
print(left_over)4 5
- 29 items can fill 4 complete groups of 6.
29 // 6therefore gives 4.- 4 groups use 24 items, leaving 5.
29 % 6therefore gives 5.- OCR would describe these operations as
29 DIV 6and29 MOD 6.
Another example
Exponentiation is another important OCR/Python difference.
level = 4
power = level ** 3
print(power)64
- Python
4 ** 3means 4 × 4 × 4. - OCR ERL would write the exponent operation using
^.
Common mistakes
- Writing
^in Python when you mean “to the power of”. - Confusing
/with//./gives ordinary division;//gives a whole-number quotient for these positive integer examples. - Using
%when you need the quotient rather than the remainder. - Ignoring normal precedence rules; use brackets when you need to make the intended order explicit.
DIV → Python //; OCR MOD → Python %; OCR ^ → Python **.Exam-ready checklist
- Select the correct arithmetic operator from the meaning of a problem.
- Translate DIV, MOD and exponentiation correctly between OCR ERL and Python.
- Trace calculations using operator precedence.
- Use quotient and remainder together in grouping/time-conversion problems.
What you have learned
- Use
+ - * /for the common arithmetic operations. DIVcorresponds to Python//.MODcorresponds to Python%.- Exponentiation uses
**in Python.