Split the Bill to the Cent

Python for AIMedium+10 XP+10

Split the Bill to the Cent

Friends split a restaurant bill equally. Money can't be split into fractions of a cent, so when it doesn't divide evenly, the first few people pay one cent more.

Task: write split_bill(total, people) that returns a list of what each person pays.

  • total is a float with at most 2 decimal places, like 10.0 or 4.35. people is at least 1.
  • The shares must add up to exactly the total, in cents.
  • Larger shares come first. Each share is a float in pounds, like 3.34.

Watch out: 4.35 * 100 in Python is 434.99999999999994, not 435. Work in whole cents, and get there safely.

Examples

total = 10.0
people = 3
returns [3.34, 3.33, 3.33]
total = 4.35
people = 3
returns [1.45, 1.45, 1.45]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run