Using Parentheses to Change the Order of Operations
The order of operations in the Python programming language is pretty much the same as the order of operations that students get taught in math class.
Dependencies
Students need to have these skills before learning this skill:
Goal
When you teach this skill, your goal is to make it so that students can write code that looks like this:
a = 1 + 2 * 3
b = (1 + 2) * 3
Activities
Here are some activities that you can do in order to teach this skill.
Writing code on the board
-
Write this code on the board:
number = 1 + 2 * 3 -
Ask students what they think that code will do.
-
Explain to students why that line of code sets
numberto7. -
Change the code so that it looks like this:
number = (1 + 2) * 3 -
Ask students what they think that code will do.
-
Explain to students why that line of code sets
numberto9.