runtime
90 / 500
question 90 Functions · hard

Give change from the till

A self-checkout pays out change in notes and coins, using as few as possible by always taking the largest denomination that still fits. Amounts are in cents, so there is no rounding. Return the change as (denomination, count) pairs, largest first, leaving out denominations that aren't used. If the customer paid too little, return None. The till can be set up with other denominations, given in any order.

Functionmake_change(price, paid, denominations=(2000, 1000, 500, 100, 25, 10, 5, 1))
price, paidwhole numbers of cents
Returnsa list of (denomination, count) tuples, largest denomination first, counts above 0; [] for exact payment; None if paid < price
Examples
callmake_change(1337, 2000)returns[(500, 1), (100, 1), (25, 2), (10, 1), (1, 3)]
callmake_change(499, 500)returns[(1, 1)]
callmake_change(800, 500)returnsNone

Loading your progress…

Give change from the till — Python practice · Runtime