Pebellslearn by building
0%
RoadmapMatrixCatalogSandboxSign in
Fundamentals  ›  Capstone Project

Capstone — Bill Splitter & Tip Calculator

Fundamentals · Project 30 minCombine everything into one working app
You're building a piece ofBill Splitter & Tip Calculator
This piece — compute_bill(): Ties every piece together to power the live receipt.
Scenario Full house: $100 of food, a 20% tip, split 4 ways, with SAVE10 applied. The engine returns every number the receipt shows.
Your task
Build compute_bill(subtotal, tip_percent, people, discount_code). It returns a dict with the full bill breakdown that powers the live receipt. Example: compute_bill(100, 20, 4, "SAVE10") → a dict where per_person is 27.0.
Additional resources

Capstone — Bill Splitter & Tip Calculator 🧾

This is it. Every function you wrote was a piece of one real app. Now you'll assemble the engine and watch the pre-built restaurant frontend (top-right, Live App tab) come alive — it calls your compute_bill() on every keystroke.

What you're building

A function that takes the raw inputs from the check…

compute_bill(subtotal, tip_percent, people, discount_code)

…and returns a dictionary of every number the receipt needs.

The business rules

Do them in this exact order — the order changes the totals:

  1. Discount comes off the subtotal first. SAVE10 → 10% off, STUDENT → 15% off, HALF → 50% off, anything else → 0%.
  2. Tip is calculated on the discounted subtotal (you tip on what you actually pay).
  3. Total = discounted subtotal + tip.
  4. Split the total between people. If people is 0, return 0.0 (don't crash).

Round every money value to 2 decimals.

The exact shape to return

The frontend reads these keys — return all nine:

{
    "subtotal":            84,      # the original
    "discount_code":       "SAVE10",
    "discount_amount":     8.4,     # dollars taken off
    "discounted_subtotal": 75.6,    # subtotal - discount
    "tip_percent":         18,
    "tip_amount":          13.61,   # tip on the discounted amount
    "total":               89.21,   # discounted + tip
    "people":              4,
    "per_person":          22.30,   # total / people
}

A cleaner discount lookup

Instead of a long if/elif chain, a dict maps each code to its rate, and .get(code, 0.0) returns 0.0 for unknown codes in one line:

DISCOUNTS = {"SAVE10": 0.10, "STUDENT": 0.15, "HALF": 0.50}
rate = DISCOUNTS.get(discount_code, 0.0)   # 0.0 if the code isn't in the dict

(This is a sneak peek at dictionaries — the star of Section 2.)

How to work

  1. Write compute_bill in the editor.
  2. Press ▶ Run to load it, then open the Live App tab and play with the restaurant form — change the tip, add people, pick a promo code. Your Python is doing the math.
  3. Press ✓ Check to run the graded tests. Green across the board = Section 1 complete. 🎉

🎯 Your turn

Fill in the four TODOs in the starter so compute_bill(...) returns the full breakdown dict.

Do the steps in this order (the order changes the totals):

  1. Discount off the subtotal — SAVE10 10% · STUDENT 15% · HALF 50% · else none
  2. Tip on the discounted subtotal
  3. Total = discounted subtotal + tip
  4. Split the total between people (0 people → per_person is 0.0)

Round every money value to 2 decimals. Example: compute_bill(100, 20, 4, "SAVE10") → each person pays 27.0.

Hint — reuse the ideas from tip (L3), discount (L4) and split (L8).

Then press ▶ Run, play with the restaurant form in the Live App, and hit ✓ Check. All green = Section 1 complete. 🎉

compute_bill.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
compute_bill(subtotal, tip_percent, people, discount_code) → dictThe full bill breakdown the frontend renders as a receipt.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.