DoAssignment study guide
A1.4 · Use Boolean, comparison, and arithmetic operators correctly
Learn to use boolean, comparison, and arithmetic operators correctly through clear examples and targeted practice.
Ontario Grade 11 Computer Science
Programming Concepts and Skills
ICS3U study topic A1.4: Boolean, comparison, and arithmetic operators
An operator tells a program what to do with one or more values. Arithmetic operators calculate with numbers, comparison operators check a relationship and produce a Boolean value, and Boolean operators combine or change Boolean values. Using an operator correctly means choosing one that matches the task and following the rules of the programming language. This lesson uses Python 3; your classroom may use a different language with different symbols or rules.
What you will learn
- Identify arithmetic, comparison, and Boolean operators in a short program.
- Trace how arithmetic and comparisons produce values, including True or False.
- Use Boolean operators to combine conditions and explain the result.
1. Arithmetic operators calculate values
Consider a school club recording how many points it has earned. The inputs might be points from two activities. An arithmetic operator performs a calculation on those values, and the result can be stored or displayed. In Python 3, common arithmetic operators include + for addition, - for subtraction, * for multiplication, / for division, and // for whole-number division that drops any fractional part.
When an expression has more than one operation, Python follows a consistent order: multiplication and division are done before addition and subtraction. Operations at the same level are generally handled from left to right. Parentheses make a grouping clear and can change which part is calculated first. For example, 3 + 4 * 2 gives 11, because the multiplication is done first; (3 + 4) * 2 gives 14.
A useful habit is to trace an expression in small steps. Check the values, the operator, and the order of calculation before deciding what is displayed. Division with / can produce a decimal value, so use it when a fractional result is appropriate; // is for a whole-number result with the fractional part removed.
- Arithmetic operators calculate new numeric values.
- Multiplication and division occur before addition and subtraction unless parentheses set a different grouping.
- Choose / or // to match the kind of result needed.
2. Comparisons produce Boolean values
A comparison asks whether a statement about values is true. In Python 3, == checks whether two values are equal; != checks whether they are not equal; <, >, <=, and >= check less than, greater than, less than or equal to, and greater than or equal to. A comparison produces one of two Boolean values: True or False.
Do not confuse = with == in Python. A single = assigns a value to a variable, as in score = 12. A double == compares values, as in score == 12. These symbols have different jobs.
Comparisons can use results of arithmetic expressions. For instance, points + bonus >= 20 first calculates the total, then checks whether the total is at least 20. The comparison is therefore a useful way to turn numeric information into a yes-or-no result.
- A comparison evaluates to True or False.
- Python uses == for equality comparison and = for assignment.
- An arithmetic calculation can be part of a comparison.
3. Boolean operators combine conditions
Boolean operators work with True and False values. Python uses and, or, and not. The expression A and B is True only when both conditions are True. A or B is True when at least one condition is True. not reverses a Boolean value: not True is False, and not False is True.
Suppose a student may borrow a game when they have a library card and the game is available. The condition card_valid and game_available expresses that both requirements must be met. If either condition is False, the combined result is False. If the rule instead allows borrowing when either of two permissions is present, or is the appropriate operator.
Parentheses can make a combined condition easier to read and can make the intended grouping explicit. First work out any comparisons inside the condition, then apply the Boolean operators. Keep each part clear: a comparison answers a question about values, and a Boolean operator combines the answers.
- and requires both conditions to be True.
- or requires at least one condition to be True.
- not changes True to False and False to True.
4. A reliable way to check an expression
Read an expression from the inside out: identify the input values, work out arithmetic, evaluate comparisons, and then combine any Boolean results. Trace variables after each assignment rather than guessing the final result. When you are unsure, write down each intermediate value in order.
Use the rule being represented to choose operators. If a task says a value must meet a minimum, use >= rather than > when equality should count. If two requirements must both hold, use and rather than or. Small choices like these affect the meaning of the program even when the code looks almost the same.
The examples below use short Python 3 programs. Their inputs and expected outputs are derived by tracing the displayed statements; the code is not claimed to have been run. Python is one classroom language, and other languages may spell or group operators differently.
- Trace values in the order the program calculates them.
- Match the comparison and Boolean operator to the exact rule.
- Use intermediate values to check the final result.
Trace for the minimum-score example
| Statement | Value after statement |
|---|---|
| points = 11 | points is 11 |
| bonus = 7 | bonus is 7 |
| score = points + bonus | score is 18 |
| complete = score >= 18 | complete is True |
| print(complete) | displays True |
Worked example
Calculate a club total
The club earns 8 points in the morning and 5 in the afternoon. Calculate the total, then display it. What output should the program produce?
Python 3
morning = 8
afternoon = 5
total = morning + afternoon
print(total)- Identify the inputsThe two input values are 8 morning points and 5 afternoon points. The arithmetic task is to add them.
- Trace the calculationThe assignment calculates 8 + 5 and stores the result in total. The next statement displays the value stored in total.
Answer: The expected output is 13.
Check: The trace gives total the value 13 before it is displayed.
Worked example
Check a minimum score
A practice task is complete when a learner earns at least 18 points. The learner earns 11 points and then receives a 7-point bonus. Determine the comparison result and displayed output.
Python 3
points = 11
bonus = 7
score = points + bonus
complete = score >= 18
print(complete)- Calculate the scoreThe program adds the bonus to the points earned. This gives a score of 18.
- Compare with the minimumThe rule says at least 18, so equality must count. The operator >= checks whether score is greater than or equal to 18. Since score is 18, the comparison is True, which print displays.
Answer: The expected output is True.
Check: Using > would make equality fail, so >= matches the stated minimum rule.
Worked example
Combine two requirements
A learner may reserve a room only if they are a club member and the room is available. The learner is a member, but the room is not available. Find the result of the combined condition.
Python 3
member = True
available = False
may_reserve = member and available
print(may_reserve)- Record the input conditionsThe member condition is True. The availability condition is False.
- Apply andThe rule requires both conditions. With and, one False condition makes the combined result False, so the program displays False. True and False = False
Answer: The expected output is False.
Check: The learner meets the membership requirement, but not both requirements, so a reservation is not allowed.
Common mistakes and how to avoid them
Using = when checking whether two values are equal in Python.
Correction: Use = to assign a value and == to compare two values.
Using > for a rule that says at least a stated value.
Correction: Use >= when equality should satisfy the rule.
Using or when both requirements must be met.
Correction: Use and when the rule requires both conditions to be True.
Assuming every division gives a whole number.
Correction: In Python 3, / can produce a decimal result; // gives a whole-number result by dropping the fractional part.
Lesson summary
- Arithmetic operators calculate numeric results.
- Comparison operators check relationships and produce True or False.
- Boolean operators combine or reverse Boolean values.
- Trace calculations and match each operator to the wording of the rule.
Check your understanding
Question 1
In Python 3, what value does 4 + 3 * 2 produce?
- 14
- 10
- 20
- correctIndex
Show answer and explanation
10
Multiplication comes before addition: 3 * 2 is 6, then 4 + 6 is 10.
Question 2
A condition must be True only when both checks are True. Which operator should combine the checks?
- or
- and
- not
- correctIndex
Show answer and explanation
and
and is True only when both conditions are True.
Question 3
In Python 3, what is the result of 12 != 12?
- True
- False
- 12
- correctIndex
Show answer and explanation
False
The values are equal, so the statement that they are not equal is False.
Key terms
- Operator
- A symbol or word that tells a program to perform an operation on values.
- Comparison
- A check of how two values relate, producing True or False.
- Boolean value
- A value that is either True or False.
- Arithmetic
- Calculation with numbers, such as addition or multiplication.
Continue through ICS3U
View the complete ICS3U Ontario Grade 11 Computer Science curriculum and lessons
- A1.3 · Use arithmetic and string assignment statements
- A1.5 · Explain one-dimensional arrays, indexes, and bounds
- A1.1 · Use variables and constants with appropriate data types
- A1.2 · Explain binary, hexadecimal, and character encoding
- A1.6 · Create and update one-dimensional arrays in a program
- A2.1 · Write a program with input, processing, and output
About this lesson and its review
Published by DoAssignment. This reviewed lesson follows Ontario Grade 11 Computer Science (ICS3U), expectation A1.4. It is a study resource, not an official curriculum publication.
Before publication, content is checked for structure, mathematical or chemical notation, calculations, course boundaries, and readability. Errors can still occur, so corrections are welcomed.