Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- import math
- cost = int(float(input("How much did the item cost?"))*100)
- moneyPaid = int(float(input("How much money did you pay?"))*100)
- moneyTypes = {"penny": 1, "nickel": 5, "dime": 10, "quarter": 25,
- "$1 bill": 100, "$5 bill": 500, "$10 bill": 1000,
- "$20 bill": 2000, "$50 bill": 5000, "$100 bill": 10000}
- amountTypes = {"penny": 0, "nickel": 0, "dime": 0, "quarter": 0,
- "$1 bill": 0, "$5 bill": 0, "$10 bill": 0,
- "$20 bill": 0, "$50 bill": 0, "$100 bill": 0}
- def getTheDifference(myCost, myMoneyPaid):
- validTypes = []
- difference = myMoneyPaid - myCost
- for price in moneyTypes.values():
- if difference >= price:
- validTypes.append(price)
- validTypes.sort(reverse = True)
- for price in validTypes:
- howManyType = math.floor(difference/price)
- amountTypes[list(moneyTypes.keys())[list(moneyTypes.values()).index(price)]] = howManyType #issue here
- difference = difference - howManyType*int(price)
- if difference == 0:
- break
- print("Your change will be: \n")
- for k, v in amountTypes.items():
- print(f"{k}: {v}")
- if cost > moneyPaid:
- print("You did not pay enough money")
- elif cost == moneyPaid:
- print("No change returned")
- else:
- getTheDifference(cost, moneyPaid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement