• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 23rd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #! python3
2. import math
3.
4. cost = int(float(input("How much did the item cost?"))*100)
5. moneyPaid = int(float(input("How much money did you pay?"))*100)
6.
7. moneyTypes = {"penny": 1, "nickel": 5, "dime": 10, "quarter": 25,
8.               "\$1 bill": 100, "\$5 bill": 500, "\$10 bill": 1000,
9.               "\$20 bill": 2000, "\$50 bill": 5000, "\$100 bill": 10000}
10. amountTypes = {"penny": 0, "nickel": 0, "dime": 0, "quarter": 0,
11.               "\$1 bill": 0, "\$5 bill": 0, "\$10 bill": 0,
12.               "\$20 bill": 0, "\$50 bill": 0, "\$100 bill": 0}
13.
14. def getTheDifference(myCost, myMoneyPaid):
15.     validTypes = []
16.     difference = myMoneyPaid - myCost
17.     for price in moneyTypes.values():
18.         if difference >= price:
19.             validTypes.append(price)
20.     validTypes.sort(reverse = True)
21.
22.     for price in validTypes:
23.         howManyType = math.floor(difference/price)
24.         amountTypes[list(moneyTypes.keys())[list(moneyTypes.values()).index(price)]] = howManyType  #issue here
25.         difference = difference - howManyType*int(price)
26.         if difference == 0:
27.             break
28.
29.     print("Your change will be: \n")
30.     for k, v in amountTypes.items():
31.         print(f"{k}: {v}")
32.
33. if cost > moneyPaid:
34.     print("You did not pay enough money")
35. elif cost == moneyPaid:
36.     print("No change returned")
37. else:
38.     getTheDifference(cost, moneyPaid)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top