Workbench / Household Numbers: the Mathematics Capstone
S8 · B1·08
Rates the Household Lives By
Stage 8, after chapter 8: unit prices across sizes and brands, ranked exactly; the monthly cost and cost per kilometre of three ways to commute; and a month's budget scaled in proportion when income changes, with a look at which lines shouldn't scale at all.
Stage 8: rates the household lives by
The brief
What you'll build. Three small comparisons built on rates: the cheapest way to buy things you use all the time, measured per kilogram across sizes and brands; what a commute really costs each month and per kilometre by motorbike, car or metro; and the month's budget scaled when income rises, keeping its proportions.
Why a real household needs this. Pack sizes and offers make prices hard to compare on purpose; commuting costs hide in fuel, parking and fares paid on different schedules; and when income changes, a plan that keeps the same proportions is a sensible first draft, though not always the right answer.
Why now. Chapter 8 gives unit rates, combining rates through totals (km ÷ km per litre = litres, then × ₹ per litre), and scaling by a ratio. Stage 4 compared two pack sizes; this stage compares any number, across brands, and adds rates with units.
What you'll have at the end. rates.py; unit prices for your regular purchases; your own commute compared; your budget scaled to a new income, with a decision about each line.
Theory to own
- One unit for everything. Why must "₹245 for 5 kg" and "₹54 for 1 kg" be brought to the same unit before comparing, and why is cross-multiplying an exact shortcut? (Chapter: "Unit prices".)
- Rates chain through units. Kilometres ÷ (kilometres per litre) = litres; litres × (rupees per litre) = rupees. Why do the units cancel like fractions? (Chapter: "Quantities per unit of another".)
- Fixed costs aren't proportional. The car's ₹1,500 of parking doesn't change with distance. Why does that make its cost per kilometre fall as you drive more? (Chapter: "Is it proportional? Test it".)
- Scaling a budget. Multiplying every line by keeps every share of income the same. Why? And why might you not want that for rent? (Chapter: "Scaling: recipes and maps".)
Build it
Step 1: by hand. Pick two things you buy in several sizes or brands and work out each option's price per kg or litre. Work out your monthly commute distance (both ways, working days) and its cost by the way you travel now.
Step 2: the code. Paise and exact fractions throughout; rounding only for display:
"""Stage 8: rates the household lives by: unit prices, the cost of a commute, and a budget scaled in proportion."""
from fractions import Fraction as F
def rupees(p):
p = round(p)
return f"₹{p // 100:,}.{p % 100:02d}"
# 1. Unit prices: the same need, different sizes and brands (paise, grams or ml).
basket = {"atta": [("Brand X 5 kg", 2_45_00, 5000), ("Brand X 10 kg", 4_70_00, 10000), ("Brand Y 1 kg", 54_00, 1000)],
"detergent": [("Brand P 1 kg", 1_99_00, 1000), ("Brand Q 2 kg", 3_75_00, 2000), ("Brand P 4 kg + 500 g free", 7_80_00, 4500)]}
for need, options in basket.items():
ranked = sorted(options, key=lambda o: F(o[1], o[2]))
cheapest = F(ranked[0][1], ranked[0][2])
print(need)
for name, paise, qty in ranked:
print(f" {name:<26} {rupees(F(paise, qty) * 1000)} per kg {'' if F(paise, qty) == cheapest else '+' + format(float(F(paise, qty) / cheapest - 1), '.1%')}")
# 2. Two ways to commute 18 km each way, 22 working days a month.
km = 2 * 18 * 22
bike = F(km, 45) * 104_80 # 45 km per litre, ₹104.80 a litre
car = F(km, 14) * 104_80 + 1_500_00 # 14 km per litre, plus ₹1,500 a month parking
metro = 2 * 22 * 4_500 # ₹45 a trip
for name, cost in (("motorbike", bike), ("car", car), ("metro", metro)):
print(f"{name:<10} {rupees(cost):>11} a month {rupees(F(cost) / km):>6} per km")
# 3. The month's budget, scaled when income changes, keeping the proportions.
budget = {"rent": 24_000_00, "food": 15_000_00, "transport": 4_000_00, "savings": 12_000_00, "other": 5_000_00}
income, new_income = sum(budget.values()), 66_000_00
k = F(new_income, income)
scaled = {item: amount * k for item, amount in budget.items()}
shares = {item: round(v) for item, v in scaled.items()}
shares["other"] += new_income - sum(shares.values()) # any rounding paise go to "other", stated
print(f"income {rupees(income)} -> {rupees(new_income)}, every line x {k}")
for item in budget:
print(f" {item:<10} {rupees(budget[item]):>11} -> {rupees(shares[item]):>11} ({float(F(budget[item], income)):.1%} of income)")
print(" total ", rupees(sum(shares.values())))
atta
Brand X 10 kg ₹47.00 per kg
Brand X 5 kg ₹49.00 per kg +4.3%
Brand Y 1 kg ₹54.00 per kg +14.9%
detergent
Brand P 4 kg + 500 g free ₹173.33 per kg
Brand Q 2 kg ₹187.50 per kg +8.2%
Brand P 1 kg ₹199.00 per kg +14.8%
motorbike ₹1,844.48 a month ₹2.33 per km
car ₹7,428.69 a month ₹9.38 per km
metro ₹1,980.00 a month ₹2.50 per km
income ₹60,000.00 -> ₹66,000.00, every line x 11/10
rent ₹24,000.00 -> ₹26,400.00 (40.0% of income)
food ₹15,000.00 -> ₹16,500.00 (25.0% of income)
transport ₹4,000.00 -> ₹4,400.00 (6.7% of income)
savings ₹12,000.00 -> ₹13,200.00 (20.0% of income)
other ₹5,000.00 -> ₹5,500.00 (8.3% of income)
total ₹66,000.00
Step 3: read the output. The 10 kg atta is the cheapest per kg, and the small 1 kg pack of the other brand costs 14.9 % more; for detergent the "500 g free" offer wins, 8 % below the 2 kg pack. For the commute, 792 km a month costs ₹1,844 by motorbike (₹2.33 a km), ₹1,980 by metro (₹2.50) and ₹7,429 by car (₹9.38), of which ₹1,500 is parking that doesn't depend on distance; drive fewer days and the car's cost per km goes up. The budget scales by so every line keeps its share of income (rent stays 40 %), and the total is exactly the new income, with any rounding paise placed in "other" by a stated rule.
Step 4: your numbers, and judgement. Run it with your own products, commute and budget. Then decide line by line: rent doesn't rise because income did, so scaling it is wrong; savings might rise by more than 10 %. Replace "scale everything" with "keep fixed costs fixed, scale the rest, and put the difference where you choose", and compare the two plans.
Senior and architect lens
- Normalise before comparing. Every comparison in this stage is one rate per option in one unit. Systems that compare plans, prices or vendors should store the quantity and unit with every price, and compute unit rates, rather than trusting labels.
- Separate fixed and variable parts. A cost model of the form "fixed + rate × usage" explains most real bills (phones, electricity, cloud services, commuting); proportional models are a special case where the fixed part is zero.
- Scaling is a default, not a decision. Proportional scaling preserves shares, which is a reasonable first draft for a budget, a capacity plan or a recipe; each line still needs a reason to scale.
Evidence
rates.pywith your own purchases, commute and budget, and its output.- Your hand calculation of one unit price and one month's commute.
- Your revised budget, with one sentence on each line you chose not to scale.
Carry forward
Stage 9, after chapter 9, brings in negative numbers: money in and money out as signed amounts, a running balance that can go below zero, an overdraft and its interest, and the difference between "down ₹500" and "₹500 less than last month".