Arithmetic, Logical & Boolean Operators (Cambridge (CIE) IGCSE Computer Science)
Revision Note
Written by: Robert Hampton
Reviewed by: James Woodhouse
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
Operator | Pseudocode | Python |
---|---|---|
Addition |
|
|
Subtraction |
|
|
Multiplication |
|
|
Division |
|
|
Modulus (remainder after division) |
|
|
Quotient (whole number division) |
|
|
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 |
---|
# ----------------------------------------------------------------------- # if the remainder of the number divided by 2 is 0, the number is even # ----------------------------------------------------------------------- # Calculate the area of the circle # Display the calculated area # ------------------------------------------------------------------------ # Loop 5 times # Check the answer and update the score
|
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
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 |
---|
# ----------------------------------------------------------- # print the result of a and b # ----------------------------------------------------------- # Take input for the score from the user # Compare the score and output the corresponding grade # ----------------------------------------------------------- |
Examiner Tips and Tricks
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
Last updated:
You've read 0 of your 5 free revision notes this week
Sign up now. It’s free!
Did this page help you?