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 = {"pennies": 1, "nickels": 5, "dimes": 10, "quarters": 25,
- "$1 bills": 100, "$5 bills": 500, "$10 bills": 1000,
- "$20 bills": 2000, "$50 bills": 5000, "$100 bills": 10000}
- amountTypes = {"pennies": 0, "nickels": 0, "dimes": 0, "quarters": 0,
- "$1 bills": 0, "$5 bills": 0, "$10 bills": 0,
- "$20 bills": 0, "$50 bills": 0, "$100 bills": 0}
- def printResult(itemsDict, lWidth, rWidth):
- print("")
- print("CHANGE RECEIVED".center(lWidth+rWidth, "-"))
- print("")
- for k, v in amountTypes.items():
- print(k.ljust(lWidth, ".") + str(v).rjust(rWidth))
- print("You have received ", end = "")
- for k, v in amountTypes.items():
- if v > 0:
- print(str(v) + " " + k + ", ", end = "")
- def getTheDifference(myCost, myMoneyPaid):
- validTypes = []
- lengthList = []
- 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
- printResult(moneyTypes, 10, 10)
- while cost > moneyPaid:
- print("You did not pay enough money")
- moneyPaid = int(float(input("How much money did you pay?"))*100)
- if cost == moneyPaid:
- print("No change returned")
- elif cost < moneyPaid:
- getTheDifference(cost, moneyPaid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement