diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-04 17:41:09 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-04 17:41:09 -0600 |
| commit | d01060b555561295bc6ae612b1b4bbab1d11c28b (patch) | |
| tree | a77980306e010156c88fcdca97af83cb12a3890c | |
| parent | 077744cced7c946e795a713ea2576c42415c79dd (diff) | |
add coins
| -rw-r--r-- | coins.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/coins.py b/coins.py new file mode 100644 index 0000000..39a37b3 --- /dev/null +++ b/coins.py @@ -0,0 +1,39 @@ +#INPUT +QUARTER = 0.25 +DIME = 0.10 +NICKEL = 0.05 +PENNY = 0.01 +amount = float(input("Enter a dollar amount?")) + +#PROCESS +def coins(total, coin): + if total < coin: + return 0 + + remainder = round(total % coin, 2) + return round((total - remainder) / coin) + +def reduce(total, coin, number_of_coins): + return round(total - (number_of_coins * coin), 2) + +def calculate(total): + quarters = coins(total, QUARTER) + total = reduce(total, QUARTER, quarters) + + dimes = coins(total, DIME) + total = reduce(total, DIME, dimes) + + nickels = coins(total, NICKEL) + total = reduce(total, NICKEL, nickels) + + pennies = coins(total, PENNY) + total = reduce(total, PENNY, pennies) + + return [quarters, dimes, nickels, pennies] + +def receipt(total): + coins = calculate(total) + return f"quarters:{coins[0]}; dimes:{coins[1]}; nickels:{coins[2]}; pennies:{coins[3]}" + +#OUTPUT +print(receipt(amount)) |
