Order of operations
An expression like could mean 20 or 14, depending on which operation you do first. Maths and Python agree on one order, so it always means 14.
Rule: Order of operations
Work out brackets first, then powers. Then multiply and divide, from left to right. Last, add and subtract, from left to right.
| Expression | Value | Why |
|---|---|---|
| 14 | multiply before adding | |
| 20 | brackets first | |
| 18 | the power applies to the 3 only | |
| 1 | divide left to right: | |
| the power comes before the minus sign |
A fraction bar groups everything above it and everything below it, as if in brackets. So , and in code that is (6 + 4) / 2. Leave out the brackets and Python works out 6 + 4 / 2 = 8.
Try it
Python follows the same order. Run the cell and match each line to the table. Division always gives a decimal, so prints as 1.0.
The last two lines show why a fraction typed into code needs brackets around its top.
Fractions
A fraction is divided by . The top is the numerator and the bottom the denominator. Multiplying and dividing are the easy cases.
Rule: Multiplying and dividing fractions
Multiply tops together and bottoms together. To divide, flip the second fraction and multiply. For example, .
To add, the bottoms must match first. Rewrite each fraction over a common denominator, then add the tops. For , both 4 and 6 go into 12:
Rule: Adding fractions
Bring both fractions over the same bottom, then add the tops. Simplify at the end by dividing top and bottom by any common factor: .
Try it
Ordinary Python numbers are decimals with a tiny rounding error, so 0.1 + 0.2 is not exactly 0.3.
Fraction from the standard library keeps fractions exact and simplifies them for you. It is a handy answer-checker.
Percentages
Percent means "per hundred", so 7% is . Turn a percentage into a decimal before you calculate: 7% of 250 is .
The change from an old value to a new one is usually given as a percentage of the old value.
Rule: Percentage change
From 80 to 92 is a change of , a rise of 15%. Always divide by the value you started from.
Growing by a percentage multiplies by , and falling by multiplies by . So a rise of 25% multiplies by 1.25, and a fall of 20% multiplies by 0.80.
Rule: Undoing a percentage rise
Here is the rise as a decimal. To undo it, divide by . Do not take off the new value. After a 20% rise a value is 120. It started at , not .
Try it
The cell works through the examples. A rise of 25% followed by a fall of 20% lands back where it started, because .
Percentage changes are not symmetric: 80 to 92 is +15%, but 92 back to 80 is about −13.04%.
Percent or percentage points?
If a rate moves from 4% to 5%, it rose by 1 percentage point: the plain difference, . As a percentage change it rose by 25%, because . Both statements are true, and people mix them up constantly. Say which one you mean.
Common mistakes
Try it
- Fractions do not add top-plus-top over bottom-plus-bottom. , not .
- Undo a rise by dividing. 120 after a 20% rise came from 100, not 96.
- Divide by the old value. A percentage change is measured against where you started.
- Bracket the top of a fraction in code. is
(6 + 4) / 2.
Fractions, percentages and order of operations
0 of 8 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- Order: brackets, powers, then left to right, then left to right. A fraction bar brackets its top and its bottom.
- ; to divide, flip and multiply; to add, use a common denominator.
Fractionfromfractionsgives exact answers in Python.- Percentage change is . A rise of multiplies by ; undo it by dividing by .
- Percentage points are a plain difference of two rates; a percentage change is relative.