W WolfCode · CSC 141

Homework: Tip Calculator

作业: 小费计算器

≈ 40 min · python-functions · Open in WolfCode

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 amount
  • compute_total(subtotal, tip_pct) — subtotal + tip
  • split_evenly(amount, people) — per-person share
  • bill_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:

  1. Tip formula is computed multiple times — change it once, find it three places.
  2. Each line does too much — hard to test pieces in isolation.
  3. Names disappear — readers re-parse the arithmetic instead of trusting compute_tip.

Acceptance criteria

  • All 7 tests pass
  • compute_total CALLS compute_tip
  • bill_summary CALLS at least 2 of the 3 helpers
  • Dict values rounded to 2 decimals