Community resourceWorksheet
J277 2.2.1 Arithmetic, comparison and Boolean operators
Part 3 of 7 · J277 2.2.1-2.2.2 · Programming fundamentals
The arithmetic, comparison and Boolean operators OCR requires, in Python notation.
Students will:
- use arithmetic operators, including integer division and remainder
- compare values with the correct comparison operator
- combine conditions with and, or and not
- distinguish assignment from comparison
- translate a written requirement into a single condition
Inside: 6 explanation cells, 3 runnable Python tasks, 3 multiple-choice questions, 1 fill-in-the-blanks cell and 2 written answers. 17 marks, about 45 minutes.
Series: J277 2.2.1-2.2.2 · Programming fundamentals, part 3 of 7.
Shared by Coding PathwayVerified teacher
- 15 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
- Updated 9 Sept 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Arithmetic, comparison and Boolean operators
Operators allow programs to calculate values and make decisions. OCR uses arithmetic, comparison and Boolean operators. Python uses == to compare equality, != for not equal, and the words and, or and not for Boolean logic.
Operator groups
- Arithmetic:
+,-,*,/,//(integer division),%(remainder),**(power). - Comparison:
==,!=,<,<=,>and>=. A comparison producesTrueorFalse. - Boolean:
andrequires both conditions,orrequires at least one, andnotreverses a Boolean value.
OCR Exam Reference Language writes integer division as DIV, remainder as MOD and exponentiation as ^. Python expresses the same operations using //, % and **. Ordinary division in Python uses /.
When Boolean operators are combined, NOT is evaluated before AND, and AND before OR. Use brackets to make the intended grouping unmistakable. For example, an alarm that requires the system to be armed and either sensor to be active needs system_armed and (door_open or window_open). Without the brackets, a window input could be combined with the wrong part of the condition.
A condition such as age >= 13 and age <= 17 must also mention age in both comparisons.
What is the value of 17 // 5 in Python?
- A3
- B3.4
- C2
- D4
Worked example: calculations and conditions
Before running the example below, predict boxes, left_over and allowed. Run it to check, then change items to 20 and explain why the remainder changes to zero.
items = 17
boxes = items // 5
left_over = items % 5
print(boxes, left_over)
age = 15
has_permission = True
allowed = age >= 13 and has_permission
print(allowed)
label 1 tests equality. The operator label 2 finds a remainder. The operator label 3 requires both conditions to be true. Ordinary division uses label 4, while raising a value to a power uses label 5 in Python.- =
- ==
- %
- //
- /
- **
- or
- and
Which condition is true only when score is from 40 to 60 inclusive?
- Ascore >= 40 or score <= 60
- Bscore >= 40 and score <= 60
- C40 <= score or 60
- Dscore > 40 and score < 60
An alarm should sound only when system_armed is true and either door_open or window_open is true. Which Python condition represents this rule?
- A(system_armed and door_open) or window_open
- Bsystem_armed or (door_open and window_open)
- Csystem_armed and (door_open or window_open)
- Dnot system_armed and (door_open or window_open)
Supported practice: quotient and remainder
A drinks supplier packs bottles into full boxes. Integer division calculates how many complete boxes can be filled, while modulo calculates how many bottles remain.
Use bottles // box_size to calculate full_boxes and bottles % box_size to calculate left_over. With 53 bottles and boxes of 6, the results should be 8 full boxes and 5 bottles left over. Another exact-division case will also be checked.
bottles = 53
box_size = 6
# 1. Calculate the number of complete boxes and store it in full_boxes.
# 2. Calculate the number of bottles remaining and store it in left_over.
Independent practice: combine three requirements
A youth activity is available only when a student is from 12 to 16 years old inclusive and consent has been given. Store the final Boolean result in eligible.
Your expression must test the lower boundary, the upper boundary and consent. The supplied values should produce True, but the checks will also try an age outside the range and a case without consent.
age = 14
consent = True
# Set eligible to the result of all three requirements.
Explain why temperature < 0 or temperature > 35 is suitable for detecting a temperature outside the safe range.
Explain what each comparison detects and why or is used.
Students type their answer here.
Correct this Python condition so it accepts ages from 11 to 18 inclusive: if age >= 11 and <= 18:
Write the complete corrected condition and briefly explain the change.
Students type their answer here.
Review
Choose an operator by asking what result is needed: a calculated number, a comparison producing True or False, or a combination of conditions. Pay particular attention to DIV///, MOD/%, inclusive boundaries and repeating the variable in both comparisons.