Dividing Fractions
To divide by a fraction, multiply by its reciprocal: flip the second fraction and multiply. This lesson explains what the reciprocal is, why "flip and multiply" works, how to divide with mixed and whole numbers, and how to answer "how many fit?" questions exactly in Python.
The reciprocal
The reciprocal of a fraction swaps its numerator and denominator. A number times its reciprocal is always 1:
| Number | Reciprocal | Check |
|---|---|---|
| 5 () | ||
| 8 | ||
| () | ||
| 0 | none | nothing times 0 gives 1 |
Flip and multiply
Examples:
Why it works
Division asks "how many of these fit into that?". How many eighths fit into three quarters? Three quarters is , so the answer is 6. Flip-and-multiply gave the same 6.
Another way: dividing by means asking how many eighths there are, and every whole has 8 of them, so dividing by is the same as multiplying by 8. In general, dividing by undoes multiplying by , and multiplying by is exactly what undoes it:
Tip: Dividing by a number less than 1 makes the result bigger (). That surprises people at first, but it makes sense: more small pieces fit.
Mixed numbers and whole numbers
Convert to improper fractions first, then flip the divisor (the second number) only:
Only the second number flips. Flipping the first, or both, gives a wrong answer.
In Python
Fraction divides exactly with /. For "how many whole pieces fit, and what is left?" use // and %, which also work on fractions:
from fractions import Fraction as F
print(F(3, 4) / F(1, 8))
print(F(2, 3) / F(4, 5))
print(6 / F(3, 4))
print((3 + F(1, 3)) / (1 + F(1, 4)))
# a 5 m roll of ribbon, cut into pieces of 3/4 m
roll, piece = F(5), F(3, 4)
print("pieces:", roll // piece, " left over:", roll % piece, "m")
print("exact ratio:", roll / piece)6
5/6
8
8/3
pieces: 6 left over: 1/2 m
exact ratio: 20/3
: six full pieces, and the leftover m is of a piece.
Complex fractions
A fraction whose top or bottom is itself a fraction is a complex fraction. It is just a division in disguise:
Dividing by zero, again
F(1, 2) / 0 raises ZeroDivisionError, because 0 has no reciprocal. Programs that compute ratios such as "average per item" must handle the empty case first:
from fractions import Fraction as F
def per_item(total, count):
if count == 0:
return None # no items: there is no average
return F(total) / count
print(per_item(F(7, 2), 3))
print(per_item(F(7, 2), 0))7/6
None
In software
- Rates and speeds. "" with fractional times, e.g. 3 km in hour is .
- Frame timing. At 60 fps each frame lasts s. A -second animation is frames.
- Undoing a scale. If a canvas is drawn at scale , mouse coordinates are divided by (multiplied by ) to map clicks back to the original drawing. This is the same "inverse" idea you will meet with matrices.
Exercises
Exercise 1: Flip and multiply
Compute in lowest terms.
Answer
Solution
Exercise 2: How many servings?
You have cups of rice. One serving is cup. How many servings is that?
Answer
6 servings
Solution
Exercise 3: Frames in a clip
A clip lasts seconds. At 24 frames per second each frame lasts s. How many frames is the clip? Check with Python.
Answer
90 frames
Solution
from fractions import Fraction as F
print((3 + F(3, 4)) / F(1, 24))90
Exercise 4: Shelves and leftovers
A board is feet long. Each shelf needs feet. Write Python that prints how many shelves you can cut and how much board is left over.
Answer
4 shelves, foot left over.
Solution
, so 4 whole shelves. They use feet, leaving foot.
from fractions import Fraction as F
board, shelf = 7 + F(1, 2), 1 + F(3, 4)
print("shelves:", board // shelf, " left:", board % shelf, "ft")shelves: 4 left: 1/2 ft
Test yourself
What is the reciprocal of ?
What is ?
- 6
In , which fraction do you flip?
- both
- neither