Last active
February 21, 2022 05:28
-
-
Save look416/180f61a54a60e02484aeb997877b526d to your computer and use it in GitHub Desktop.
VendingMachine
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 calculateChange(balance, amount): | |
if balance < amount: | |
raise Exception("Insufficient funds") | |
denominator = [100,50,20,10,5,1] | |
result = [] | |
change = balance - amount | |
for deno in denominator: | |
num = change // deno | |
result.append(num) | |
change = change % deno | |
return result | |
print(calculateChange(76, 55)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment