Homework: Tip Calculator
作业: 小费计算器
Four functions. Three small helpers and one orchestrator. The grade is for decomposition as much as correctness.
The four functions
compute_tip(subtotal, tip_pct)— tip amountcompute_total(subtotal, tip_pct)— subtotal + tipsplit_evenly(amount, people)— per-person sharebill_summary(subtotal, tip_pct, people)— dict with all three
The right shape
See how each helper does ONE thing
Why FOUR functions instead of one?
You could write everything in one bill_summary. It would work.
But three things would suffer:
- Tip formula is computed multiple times — change it once, find it three places.
- Each line does too much — hard to test pieces in isolation.
- Names disappear — readers re-parse the arithmetic instead of trusting
compute_tip.
Acceptance criteria
- All 7 tests pass
compute_totalCALLScompute_tipbill_summaryCALLS at least 2 of the 3 helpers- Dict values rounded to 2 decimals