DoAssignment study guide

B1.4 · Follow order of operations in expressions

Learn to follow order of operations in expressions through clear examples and targeted practice.

Ontario Grade 10 Computer Science

Introduction to Programming

ICS2O study topic B1.4: Follow order of operations in expressions

A computer follows the structure of an expression; it does not guess what a person intended. Imagine a club buying several identical packs and then paying a separate fee. The pack cost must be calculated before the fee is added. Order of operations gives people and computers a shared way to interpret such calculations. In a program, input is information supplied to the program, process is the calculation performed, and output is the result displayed. This lesson focuses only on following order of operations in expressions. Classroom programming languages can differ in how they write operations, so use the notation taught in your class.

What you will learn

  • Explain why a shared order is needed to evaluate expressions consistently.
  • Apply parentheses, exponents, multiplication and division, and addition and subtraction in the correct order.
  • Work from left to right when operations share the same level.
  • Trace a short Python 3 expression and predict its output.

Why a shared order matters

Consider 8+3×48 + 3 \times 4. Adding first would give 4444, while multiplying first gives 2020. A written expression needs one agreed meaning, so multiplication is done before addition.
Use this order: calculate inside parentheses first; then calculate exponents; then do multiplication and division from left to right; finally do addition and subtraction from left to right. Multiplication and division share a level, as do addition and subtraction. Neither operation in a shared pair always comes first.
The phrase “Please Excuse My Dear Aunt Sally” is sometimes used to remember parentheses, exponents, multiplication, division, addition, and subtraction. Remember that multiplication and division must still be handled left to right, and so must addition and subtraction.
  • Parentheses group a calculation to do first.
  • Exponents are handled after parentheses.
  • Multiplication and division share a level; addition and subtraction share a level.
  • For operations at the same level, move from left to right.

Apply the rules one operation at a time

A reliable approach is to identify the next operation allowed by the rules, calculate it, and rewrite the expression. Keep the remaining parts in their original order. This makes your reasoning visible and helps prevent choosing an operation simply because it seems easier.
Suppose a club buys four packs at five dollars each and then pays a two-dollar fee. The pack cost is represented by 4×54 \times 5, and the fee is added afterward: 4×5+24 \times 5 + 2. Multiplication comes before addition, so the expression matches the described plan.
Parentheses can change the grouping. In 4×(5+2)4 \times (5 + 2), the addition is done first, then its result is multiplied by four. These parentheses are not decoration: they direct the calculation and give the expression a different value.
  • Translate the situation into an expression before calculating.
  • Calculate one operation at a time and preserve the remaining order.
  • Use parentheses when a group must be calculated before operations outside it.

Read an expression in Python 3

The same order-of-operations reasoning applies when following a program expression. In Python 3, multiplication is written with an asterisk, as in `2 * 3`. Python 3 writes an exponent using two asterisks: ``. For example, `2 3` means two raised to the third power, which is 88. Other classroom languages may write an exponent differently.
Here is an input–process–output situation: a number is supplied as input, an expression calculates a result as the process, and a print instruction displays the output. In the worked code, the input is assigned directly to a variable so the calculation can be traced clearly. The code is shown as text and has not been executed.
  • Follow the expression rules on paper and when tracing code.
  • Read the operators and parentheses carefully.
  • Treat displayed code as text to reason about; classroom languages can differ.

Check a result and practise

Before accepting an answer, check the order: parentheses, exponents, multiplication and division from left to right, then addition and subtraction from left to right. Show intermediate values for a longer expression instead of jumping to the result.
For practice, evaluate 7+2×67 + 2 \times 6, then evaluate (7+2)×6(7 + 2) \times 6. The expressions use the same numbers but different grouping. Next, evaluate 20÷5×320 \div 5 \times 3 from left to right because division and multiplication share a level. You can check each answer by writing down the operation performed at each stage.
Finally, ask whether the result fits the situation. If an expression describes a purchase, for example, check that you multiplied the number of items by the price before adding a separate fee. A sensible context check can reveal a calculation mistake, but it does not replace following the rules.
  • Write intermediate values to make your method easy to check.
  • Parentheses can make two expressions with the same numbers mean different calculations.
  • Use the situation as a final reasonableness check.

Trace for the Python 3 example

StageValue or calculation
Inputnumber = 3
Exponent3 2 gives 9
Multiply and add2 * 9 + 1 gives 19
Expected output19

Worked example

Multiply before adding

A club buys four packs that cost five dollars each, then pays a two-dollar fee. Find the total represented by 4×5+24 \times 5 + 2.
  1. Identify the first operation
    The expression has multiplication and addition. Multiplication comes before addition, so first find the cost of the four packs.
    4×5=204 \times 5 = 20
  2. Add the fee
    The remaining operation adds the two-dollar fee to the pack cost.
    20+2=2220 + 2 = 22
Answer: The total is 22 dollars.
Check: Four packs at five dollars each cost 20 dollars. Adding the two-dollar fee gives 22 dollars.

Worked example

Parentheses change the grouping

Evaluate 4×(5+2)4 \times (5 + 2) and compare its grouping with the first example.

Python 3

result = 4 * (5 + 2)
print(result)
  1. Calculate inside parentheses
    The parentheses group five and two, so add them before multiplying by four.
    5+2=75 + 2 = 7
  2. Multiply the result
    Now multiply the grouped sum by four.
    4×7=284 \times 7 = 28
Answer: The expression equals 28. It differs from the first example because the parentheses put addition before multiplication.
Check: The parentheses require the sum to be calculated first. Without them, multiplication would happen before addition.

Worked example

Trace an exponent in Python 3

In the Python 3 example, the input value is 3. Follow the expression and predict the output.

Python 3

number = 3
result = 2 * number ** 2 + 1
print(result)
  1. Find the exponent
    The input is 3. Python 3 writes an exponent with two asterisks. Calculate the power before multiplication and addition.
    32=93^2 = 9
  2. Multiply, then add
    Multiplication comes before addition. Multiply the power by two, then add one.
    2×9+1=192 \times 9 + 1 = 19
Answer: The expected output is 19.
Check: The trace uses input 3, calculates its square as 9, then calculates two times 9 plus 1. The displayed code has not been executed.

Common mistakes and how to avoid them

Adding before multiplying in an expression such as 8+3×48 + 3 \times 4.
Correction: Multiply first, then add. The expression equals 2020.
Always doing multiplication before division, even when division appears first.
Correction: Multiplication and division share a level. Work from left to right.
Always doing addition before subtraction.
Correction: Addition and subtraction share a level. Work from left to right.
Treating parentheses as optional when they change which operations are grouped.
Correction: Calculate inside parentheses first; they can change the expression's meaning.
Reading Python 3's `` as multiplication.
Correction: In Python 3, `` represents an exponent. Calculate the exponent before multiplication, division, addition, or subtraction.

Lesson summary

  • Calculate inside parentheses first, then exponents.
  • Next handle multiplication and division from left to right.
  • Finally handle addition and subtraction from left to right.
  • Apply the same reasoning when tracing an expression in a program, remembering that classroom languages can use different notation.

Check your understanding

Question 1

What is the value of 6+2×56 + 2 \times 5?
  1. 40
  2. 16
  3. 25
  4. 22
Show answer and explanation
16
Multiply first: two times five is ten. Then add six to get 16.

Question 2

What is the value of 18÷3×218 \div 3 \times 2?
  1. 3
  2. 12
  3. 9
  4. 6
Show answer and explanation
12
Division and multiplication share a level, so work left to right: 18 divided by 3 is 6, then 6 times 2 is 12.

Question 3

In the Python 3 expression `2 * (3 + 1)`, which part is calculated first?
  1. The multiplication by 2
  2. The addition inside the parentheses
  3. The print instruction
  4. The operations from right to left
Show answer and explanation
The addition inside the parentheses
Parentheses are handled before multiplication, so calculate 3 plus 1 first.

Key terms

Expression
Numbers and operation symbols arranged to represent a calculation.
Parentheses
Symbols that group part of an expression and indicate that the grouped calculation is done first.
Input
Information supplied to a program.
Process
The work a program performs on its input.
Output
Information a program displays or produces.

Continue through ICS2O

View the complete ICS2O Ontario Grade 10 Computer Science curriculum and lessons

Tutor support for B1.4 · Follow order of operations in expressions

Working on B1.4 · Follow order of operations in expressions in ICS2O? Bring the question and your own attempt. In a live session, you can represent the quantities clearly, explain the operation you chose, and estimate whether the answer is reasonable. Ask about the first step that does not make sense, then try a similar question yourself.

Explore coding tutoring · Request an eligible free 30-minute introduction. Your request is matched by subject and language; a tutor must accept before a time is confirmed.

برای مبحث B1.4 · رعایت ترتیب عمل‌ها در عبارت‌ها در درس ICS2O، سؤال و تلاش خود را همراه بیاورید. در جلسه می‌توانید کمیت‌ها را روشن نمایش دهید، دلیل انتخاب عمل را توضیح دهید و معقول بودن پاسخ را برآورد کنید. راهنمای معلم برنامه‌نویسی را ببینید یا جلسهٔ معارفهٔ رایگان ۳۰ دقیقه‌ای درخواست کنید. زمان جلسه پس از پذیرش معلم قطعی می‌شود.

About this lesson and its review

Published by DoAssignment. This reviewed lesson follows Ontario Grade 10 Computer Science (ICS2O), expectation B1.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.

Official curriculum reference

Report a correction or ask a question