Mini-Project: Tip Splitter
Time to combine everything: numbers, math, rounding, and functions. You will build a tiny tool that figures out how much each person owes for a meal once a tip is added.
The plan
Given the bill total, the number of people, and a tip_percent (like 20 for twenty percent), the per-person amount is:
- Add the tip:
total + total * (tip_percent / 100). A 20 percent tip on 100 gives 120. - Split it: divide by
people. - Round to cents with the built-in
round(value, 2), which keeps 2 decimal places.
grand = 100 + 100 * (20 / 100) # 120.0
print(grand / 4) # 30.0
print(round(31.666, 2)) # 31.67Wrapping it in a function means you can reuse it for any bill, and the auto-grader can check it with different numbers.
Write a function bill_split(total, people, tip_percent) that adds the tip to total, splits the result evenly among people, and returns the per-person amount rounded to 2 decimal places with round(..., 2). For example bill_split(100, 4, 20) should return 30.0, and bill_split(50, 3, 10) should return 18.33. After defining it, print bill_split(100, 4, 20).
This lesson is locked
Lessons open one at a time. Finish the previous lesson to unlock this one.