Order of operations, and names for numbers
Why this matters
What is 4 + 3 × 2? If one person gets 14 and another gets 10, a calculation means two things, and nobody can trust it. So everyone agrees on an order. Python follows the same order, and every formula in AI depends on it. This lesson shows the order, how brackets override it, and how to give numbers names so a long calculation reads like plain sense.
- Work a calculation in the agreed order: brackets, powers, multiply and divide, then add and subtract
- Place brackets to make a calculation mean what you intend
- Give numbers names in Python with variables, and print a label with a value
- Read a model's formula, such as w * x + b, in the right order
The math: one calculation, one answer
Purpose. A calculation has to mean the same thing to everyone who reads it, so there's an agreed order:
- Brackets first: anything inside brackets is worked out before the rest.
- Powers, like 3² (you'll meet them properly in the powers lesson).
- Multiply and divide, from left to right.
- Add and subtract, from left to right.
So in 4 + 3 × 2 − 1, the multiplication goes first: 3 × 2 = 6. That leaves 4 + 6 − 1, which you work left to right: 10, then 9.
Brackets override the order. If you meant "4 plus 3, then times 2", write it: (4 + 3) × 2 = 14. Brackets say "do this part first", whatever it holds.
The flow below works 4 + 3 × 2 − 1 one operation at a time, and its picture draws the calculation as a tree. Each operation sits above the two numbers it works on, so the one that happens last is at the top. Each step folds one operation into its answer, from the bottom up, until a single number is left.