You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the three types of operators you need to know for OCR J277 Section 2.3: arithmetic operators, comparison operators, and Boolean operators (AND, OR, NOT). Operators are the building blocks of expressions and conditions in programming.
Arithmetic operators perform mathematical calculations on numerical values.
| Operator | OCR Pseudocode | Python | Description | Example | Result |
|---|---|---|---|---|---|
| Addition | + | + | Adds two values | 7 + 3 | 10 |
| Subtraction | - | - | Subtracts right from left | 7 - 3 | 4 |
| Multiplication | * | * | Multiplies two values | 7 * 3 | 21 |
| Division | / | / | Divides left by right (real division) | 7 / 2 | 3.5 |
| Integer division | DIV | // | Divides and rounds down to whole number | 7 DIV 2 | 3 |
| Modulus | MOD | % | Returns the remainder after division | 7 MOD 2 | 1 |
| Exponentiation | ^ | ** | Raises to a power | 2 ^ 3 | 8 |
DIV and MOD are the most commonly tested arithmetic operators in the OCR exam.
DIV gives the whole number part of a division:
17 DIV 5 = 3 (because 5 goes into 17 three whole times)10 DIV 3 = 3MOD gives the remainder:
17 MOD 5 = 2 (because 17 = 5 × 3 remainder 2)10 MOD 3 = 1Common uses of MOD:
number MOD 2 == 0number MOD n == 01234 MOD 10 = 4OCR Exam Tip:
DIVandMODappear in almost every Paper 2 exam. Practise until you can calculate them instantly. Remember:DIV= quotient,MOD= remainder. For example,23 DIV 7 = 3and23 MOD 7 = 2because 23 = 7 × 3 + 2.
Comparison operators compare two values and return a Boolean result (true or false).
| Operator | OCR Pseudocode | Python | Description | Example | Result |
|---|---|---|---|---|---|
| Equal to | == | == | Checks if values are equal | 5 == 5 | true |
| Not equal to | != | != | Checks if values are not equal | 5 != 3 | true |
| Greater than | > | > | Left is greater than right | 5 > 3 | true |
| Less than | < | < | Left is less than right | 5 < 3 | false |
| Greater than or equal to | >= | >= | Left is greater than or equal to right | 5 >= 5 | true |
| Less than or equal to | <= | <= | Left is less than or equal to right | 3 <= 5 | true |
OCR Exam Tip: A very common mistake is confusing
=(assignment) with==(comparison).x = 5sets x to 5.x == 5checks if x is equal to 5. In pseudocode, OCR uses==for comparison and=for assignment.
Boolean operators combine or modify Boolean values. They are essential for building complex conditions in selection and iteration statements.
Returns true only if both conditions are true.
| A | B | A AND B |
|---|---|---|
| true | true | true |
| true | false | false |
| false | true | false |
| false | false | false |
Returns true if at least one condition is true.
| A | B | A OR B |
|---|---|---|
| true | true | true |
| true | false | true |
| false | true | true |
| false | false | false |
Reverses (inverts) a Boolean value.
| A | NOT A |
|---|---|
| true | false |
| false | true |
OCR Pseudocode:
age = int(input("Enter age: "))
hasTichet = true
if age >= 18 AND hasTicket == true then
print("Entry allowed")
elseif age < 18 OR hasTicket == false then
print("Entry denied")
endif
Python:
age = int(input("Enter age: "))
has_ticket = True
if age >= 18 and has_ticket:
print("Entry allowed")
elif age < 18 or not has_ticket:
print("Entry denied")
The flow of an entry decision built from comparison and Boolean operators can be drawn as an IF/ELSE flowchart:
flowchart TD
A([Start]) --> B[Read age, hasTicket]
B --> C{"age >= 18<br/>AND<br/>hasTicket == true?"}
C -->|true| D[print 'Entry allowed']
C -->|false| E{"age < 18<br/>OR<br/>hasTicket == false?"}
E -->|true| F[print 'Entry denied']
E -->|false| G[no output]
D --> H([End])
F --> H
G --> H
When multiple operators appear in a single expression, they are evaluated in a specific order:
| Priority | Operators |
|---|---|
| 1 (highest) | Parentheses () |
| 2 | Exponentiation ^ / ** |
| 3 | Multiplication, Division, DIV, MOD |
| 4 | Addition, Subtraction |
| 5 | Comparison operators (==, !=, <, >, etc.) |
| 6 | NOT |
| 7 | AND |
| 8 (lowest) | OR |
Example: What is 3 + 4 * 2?
Answer: 11 (not 14), because multiplication is done before addition.
To override precedence, use parentheses: (3 + 4) * 2 = 14.
+, -, *, /, DIV, MOD, ^.==, !=, <, >, <=, >=.AND, OR, NOT.DIV and MOD are the most commonly tested operators.OCR Exam Tip: In the exam, if you are unsure about precedence, use parentheses to make your intention clear. The examiner will accept
(a + b) * cand this avoids any ambiguity. Clarity in your code demonstrates good programming practice.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.