Created
March 10, 2016 07:17
-
-
Save ntijoh-daniel-berg/dc7653184a684c5cb744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def change_o_matic(price, amount_paid): | |
amount_due = amount_paid - price | |
if amount_due < 0: | |
raise ValueError("amount paid ({0}) must not be less than price ({1}) ".format(amount_paid, price)) | |
change = {1000: 0, 500: 0, 200: 0, 100: 0, | |
50: 0, 20: 0, 10: 0, 5: 0, 2: 0, 1: 0 } | |
denominations = sorted(change.keys(), reverse=True) | |
for den in denominations: | |
while amount_due >= den: | |
change[den] += 1 | |
amount_due -= den | |
return change |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment