Arithmetic, Logical & Boolean Operators (Cambridge International IGCSE Computer Science)
What is an operator?
-
An operator is a symbol used to instruct a computer to perform a specific operation on one or more values
-
Examples of common operators include:
- Arithmetic
- Logical
- Boolean
Arithmetic Operators
Spec point —
8.1.1· "(f) Understand and use arithmetic, logical and Boolean operators"
Arithmetic Operators
| Operator | Pseudocode | Python |
|---|---|---|
| Addition | + | + |
| Subtraction | - | - |
| Multiplication | * | * |
| Division | / | / |
| Modulus (remainder after division) | MOD | % |
| Quotient (whole number division) | DIV | // |
| Exponentiation (to the power of) | ^ | ** |
-
To demonstrate the use of common arithmetic operators, three sample programs written in Python are given below
-
Comments have been included to help understand how the arithmetic operators are being used
- Arithmetic operators #1 - a simple program to calculate if a user entered number is odd or even
- Arithmetic operators #2 - a simple program to calculate the area of a circle from a user inputted radius
- Arithmetic operators #3 - a simple program that generates 5 maths questions based on user inputs and gives a score of how many were correctly answered at the end
| Python code |
|---|
Logical Operators
Spec point —
8.1.1· "(f) Understand and use arithmetic, logical and Boolean operators"
Logical Operators
| Operator | Pseudocode | Python |
|---|---|---|
| Equal to | == | == |
| Not equal to | <> | != |
| Less than | < | < |
| Less than or equal to | <= | <= |
| Greater than | > | > |
| Greater than or equal to | >= | >= |
Boolean Operators
Spec point —
8.1.1· "(f) Understand and use arithmetic, logical and Boolean operators"
Boolean Operators
-
A Boolean operators is a logical operator that can be used to compare two or more values and return a Boolean value (True or False) based on the comparison
-
There are 3 main Boolean values:
- AND: Returns True if both conditions are True
- OR: Returns True if one or both conditions are True
- NOT: Returns the opposite of the condition (True if False, False if True)
-
To demonstrate the use of common Boolean operators, three sample programs written in Python are given below
-
Comments have been included to help understand how the Boolean operators are being used
- Common Boolean operators #1 - a simple program that assigns Boolean values to two variables and outputs basic comparisons
- Common Boolean operators #2 - a simple program to output a grade based on a users score
- Common Boolean operators #3 - a simple program reads a text files and searches for an inputted score
| Python code |
|---|
Exam Hint
- Boolean operators are often used in conditional statements such as if, while, and for loops
- Boolean operators can be combined with comparison operators
- Be careful when using the NOT operator, as it can sometimes lead to unexpected results
- It is always a good idea to test your code with different inputs to ensure that it works as expected
Was this revision note helpful?
Build on this topic