Skip to content

Instantly share code, notes, and snippets.

@look416
Last active February 21, 2022 05:28
Show Gist options
  • Save look416/180f61a54a60e02484aeb997877b526d to your computer and use it in GitHub Desktop.
Save look416/180f61a54a60e02484aeb997877b526d to your computer and use it in GitHub Desktop.
VendingMachine
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