Proportions
A proportion says that two ratios are equal, like . If you know three of the four numbers, you can find the fourth. This lesson solves proportions with cross multiplication, sets up word problems correctly, and uses proportions to scale recipes, resize images and map coordinates between screens.
Two equal ratios
The test for a true proportion is the same cross-product test you used for equivalent fractions:
is a proportion because and .
Solving for the missing number
Cross multiply, then divide:
Always check by putting the answer back: ? Both are 0.6. ✓
Setting up word problems
The key is to keep the same units in the same positions on both sides.
A car uses 6 litres of fuel for 80 km. How much for 300 km?
A map's scale is . Two towns are 18 cm apart on the map. How far apart are they really?
Tip: Write the units next to every number while setting up. If "litres over km" is on the left, it must be "litres over km" on the right too.
Proportions in Python
A small solver for , kept exact with Fraction:
from fractions import Fraction as F
def fourth(a, b, c):
"""Solve a/b = c/x for x."""
return F(b) * c / a
print(fourth(3, 5, 12)) # 3/5 = 12/x -> x = 20
print(fourth(6, 80, 22.5)) # 6 L/80 km = 22.5 L/x km (float in)
print(fourth(6, 80, F("22.5"))) # same, kept exact
print(fourth(1, 25000, 18) / 100_000, "km") # map scale, cm -> km
# check a proportion with cross products
def is_proportion(a, b, c, d):
return a * d == b * c
print(is_proportion(4, 10, 6, 15), is_proportion(4, 10, 6, 14))20
300.0
300
9/2 km
True False
Passing the float 22.5 gave the float 300.0: mixing a Fraction with a float always produces a float. Passing F("22.5") keeps the whole calculation exact and gives 300. 9/2 km is 4.5 km.
Scaling a recipe
A recipe for 4 people becomes a recipe for 6 people with the ratio . Every ingredient keeps the same proportion to the others:
from fractions import Fraction as F
recipe = {"rice (cups)": F(3, 2), "water (cups)": F(3), "salt (tsp)": F(3, 4), "onions": F(1)}
serves, wanted = 4, 6
factor = F(wanted, serves)
for item, amount in recipe.items():
new = amount * factor
whole, rest = divmod(new.numerator, new.denominator)
shown = f"{whole} {F(rest, new.denominator)}" if whole and rest else str(new)
print(f"{item:13} {str(amount):>4} -> {shown}")rice (cups) 3/2 -> 2 1/4
water (cups) 3 -> 4 1/2
salt (tsp) 3/4 -> 1 1/8
onions 1 -> 1 1/2
Every amount was multiplied by the same factor , so the ratios between ingredients (twice as much water as rice, for example) stay the same.
Resizing and coordinate mapping
Keeping an image's proportions when resizing is a proportion: . Mapping a mouse position from a 1920-wide window to a 1280-wide canvas uses the same proportion: . This is the same "map one range to another" idea behind linear interpolation.
In software
- Responsive layouts: CSS
aspect-ratio: 16 / 9keeps width and height proportional. - Thumbnails: scale down to width 400 → height .
- Progress estimates: "processed 1.2 GB in 40 s, so 6 GB takes 200 s" assumes a constant rate, which is a proportion.
- Charts map data values to pixel positions with a proportion (a linear scale).
Exercises
Exercise 1: Solve it
Solve .
Answer
Solution
Exercise 2: Typing speed
You type 340 words in 5 minutes. At the same rate, how long does a 1700-word essay take?
Answer
25 minutes
Solution
Exercise 3: Thumbnail size
A portrait photo is scaled to a height of 512 px. How wide is the thumbnail?
Answer
384 px
Solution
, so .
Exercise 4: Scale for a party
Scale the same recipe (for 4 people: cups rice, 3 cups water, tsp salt, 1 onion) to 10 people. Work it out by hand, then write a function scale(recipe, serves, wanted) that returns the new amounts.
Answer
rice cups, water cups, salt tsp, onions .
Solution
The factor is .
from fractions import Fraction as F
def scale(recipe, serves, wanted):
factor = F(wanted, serves)
return {item: amount * factor for item, amount in recipe.items()}
recipe = {"rice": F(3, 2), "water": F(3), "salt": F(3, 4), "onions": F(1)}
for item, amount in scale(recipe, 4, 10).items():
print(item, amount)rice 15/4
water 15/2
salt 15/8
onions 5/2
Test yourself
Solve .
5 pens cost 3.50. How much do 8 pens cost?
- 5.60
- 4.50
- 6.00
- 5.25
Which is a true proportion?