Last active
November 21, 2022 19:41
-
-
Save Spebby/2718019218a406719e97eeff675708f2 to your computer and use it in GitHub Desktop.
dolla maker
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
#!/usr/bin/env python3 | |
"""currency project""" | |
billNames = { | |
0: "hundred", | |
1: "fifty", | |
2: "twenty", | |
3: "ten", | |
4: "five", | |
5: "one", | |
10: "hundreds", | |
12: "twenties", | |
15: "ones", | |
} | |
coinNames = { | |
0: "quarter", | |
1: "dime", | |
2: "nickel", | |
3: "penny", | |
10: "quarters", | |
11: "dimes", | |
13: "pennies", | |
} | |
# scrapes the input for just int values | |
def Scrape(inputString): | |
tempString = "0" | |
# ^ adding as a failsafe | |
for char in inputString: | |
if char in ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."): | |
tempString += char | |
return tempString | |
money = float(Scrape(input())) | |
cash = int(money) | |
coins = int(round((money - cash) * 100)) | |
# storing as an int to avoid floating point errors. | |
billsCounter = [0, 0, 0, 0, 0, 0] | |
_TempBills = cash % 100 | |
billsCounter[0] = (cash - _TempBills) / 100 | |
billsCounter[1] = (_TempBills - (_TempBills % 50)) / 50 | |
_TempBills = _TempBills % 50 | |
billsCounter[2] = (_TempBills - (_TempBills % 20)) / 20 | |
_TempBills = _TempBills % 20 | |
billsCounter[3] = (_TempBills - (_TempBills % 10)) / 10 | |
_TempBills = _TempBills % 10 | |
billsCounter[4] = (_TempBills - (_TempBills % 5)) / 5 | |
_TempBills = _TempBills % 5 | |
billsCounter[5] = _TempBills | |
coinsCounter = [0, 0, 0, 0] | |
_TempCoins = coins % 25 | |
coinsCounter[0] = (coins - _TempCoins) / 25 | |
coinsCounter[1] = (_TempCoins - (_TempCoins % 10)) / 10 | |
_TempCoins = _TempCoins % 10 | |
coinsCounter[2] = (_TempCoins - (_TempCoins % 5)) / 5 | |
_TempCoins = _TempCoins % 5 | |
coinsCounter[3] = _TempCoins | |
# the above fills coinCounter with the optimial denominations of coins. | |
# boilerplate could be reduced with a recursive function; I'm too lazy to write one at the moment | |
# would be nice if Python had an equivalent to a standard for loop instead of having to enumerate | |
for i, item in enumerate(billsCounter): | |
if item > 0: | |
if item > 1: | |
i += 10 | |
print(f"{int(item)} {billNames[i]}") | |
i -= 10 | |
for i, item in enumerate(coinsCounter): | |
if item > 0: | |
if item > 1: | |
i += 10 | |
print(f"{int(item)} {coinNames[i]}") | |
i -= 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment