Tip Splitter 🧾
Take a bill, a tip percentage, and a number of people, and work out what each person owes. It sounds trivial until you meet money's favourite trap: rounding. This project makes you decide, on purpose, how to handle the pennies.
📋 Build this
- Read the bill amount, the tip percentage, and the number of people.
- Compute the tip, the total, and the per-person share.
- Show every figure to exactly two decimal places.
- Make sure the per-person shares add up to the total (no lost penny).
Hints, if you want them
Try the spec cold first. Open a hint only when you are properly stuck; the struggle is where the learning is.
Hint 1: The arithmetic
tip = bill * (percent / 100); total = bill + tip; each = total / people. Convert the inputs with
float() and int().Hint 2: Two decimal places
Use an f-string format spec:
f"{total:.2f}" shows two decimals (Lesson 4). This is display formatting, not the stored value.Hint 3: The lost penny
If you round each share independently, they may not sum to the total. The honest fix: round the total, give everyone the floor share, and add the leftover pennies to the first person. See the reference.
The reference solution
Yours does not need to match this. There are many good ways to build any of these. Compare only after you have your own working.
Reveal the reference solution
bill = float(input("Bill amount: "))
percent = float(input("Tip percent: "))
people = int(input("How many people: "))
tip = round(bill * percent / 100, 2)
total = round(bill + tip, 2)
# work in whole pennies so nothing is lost to rounding
total_pennies = round(total * 100)
base = total_pennies // people
leftover = total_pennies - base * people
shares = [base + (1 if i < leftover else 0) for i in range(people)]
print(f"Tip: {tip:.2f}")
print(f"Total: {total:.2f}")
for i, pennies in enumerate(shares, start=1):
print(f"Person {i}: {pennies / 100:.2f}")
print(f"Sum of shares: {sum(shares) / 100:.2f}")
Bill amount: 87.50
Tip percent: 15
How many people: 4
Tip: 13.12
Total: 100.62
Person 1: 25.16
Person 2: 25.16
Person 3: 25.15
Person 4: 25.15
Sum of shares: 100.62Stretch goals
- Let the user round the tip up to the nearest pound for a tidy total.
- Support an uneven split where some people cover more.
- Use the
decimalmodule for exact money (Lesson 3).