Syllabus Lesson 5 of 141 · The blind start
The blind start

Baseline 4: the missing cent

AI off This is a baseline exam. The tutor is switched off and there are no hints. Work alone, the way you would with no assistant open. Nothing here is a trick: every rule is written in the exercise. Your result is only compared with your own final exam at the end of the course.

A shared-expenses app splits bills between friends. A user reports that splitting 1 euro three ways loses a cent. The ticket includes one example; the code is below.

def split_bill(total, people):
    share = total // people
    return [share] * people

split_bill(100, 3)   # [33, 33, 33], expected [34, 33, 33]
Your turn

Fix split_bill(total, people) in the starter. It splits a bill of total cents (a whole number) between people (at least 1). The rules: the shares add up exactly to total, no two shares differ by more than 1 cent, and the list is in order, largest first. The bug report says split_bill(100, 3) returns [33, 33, 33] but should be [34, 33, 33]. The hidden tests try hundreds of totals and group sizes, and also refunds: total can be negative, and the same three rules apply.

AI off: no tutor, hints or worked solution on this one. Your own thinking only.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.