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).
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.