From 8ea27eaec70db601a0eec96a6502e04369d04415 Mon Sep 17 00:00:00 2001 From: Oleksandr Sapozhnik Date: Wed, 12 Oct 2022 09:29:11 +0000 Subject: [PATCH] Update app.py When we put 2.53, the result will be 10 quarters and 2 pennies. But should be 3 pennies. The issue is due to 1) amount *100 which will be 252.999 2) int that makes truncation. So it's better to use round here instead of int. --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 5f08c3a..7d86bc0 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ def change(amount): # divide the amount*100 (the amount in cents) by a coin value # record the number of coins that evenly divide and the remainder coin = coins.pop() - num, rem = divmod(int(amount*100), coin) + num, rem = divmod(round(amount*100), coin) # append the coin type and number of coins that had no remainder res.append({num:coin_lookup[coin]})