• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #! python3
2. import math
3.
4. cost = float(input("How much did the item cost?"))
5. moneyPaid = float(input("How much money did you pay?"))
6.
7. moneyTypes = {"penny": .01, "nickel": .05, "dime": .10, "quarter": .25,
8.               "\$1 bill": 1.00, "\$5 bill": 5.00, "\$10 bill": 10.00,
9.               "\$20 bill": 20.00, "\$50 bill": 50.00, "\$100 bill": 100.00}
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.     difference = float('%.2f' % difference)
18.     for price in moneyTypes.values():
19.         if difference >= price:
20.             validTypes.append(price)
21.     validTypes.sort(reverse = True)
22.     for item in validTypes:
23.         item = float(item)
24.     print(validTypes)
25.
26.     for price in validTypes:
27.         print(difference)
28.         print(type(difference))
29.         print(type(price))
30.         howManyType = math.floor(difference/price)
31.         amountTypes[list(moneyTypes.keys())[list(moneyTypes.values()).index(price)]] = howManyType  #issue here
32.         difference = difference - howManyType*int(price)
33.         difference = float('%.2f' % difference)
34.         print(difference)
35.         if difference == 0:
36.             break
37.
38.     print("Your change will be: \n")
39.     for k, v in amountTypes.items():
40.         print(f"{k}: {v}")
41.
42.
43.
44. if cost > moneyPaid:
45.     print("You did not pay enough money")
46. elif cost == moneyPaid:
47.     print("No change returned")
48. else:
49.     getTheDifference(cost, moneyPaid)
50.
51.
52.
53. """def getTheDifference(myCost, myMoneyPaid):
54.     getcontext().prec = 2
55.     validTypes = []
56.     difference = myMoneyPaid - myCost
57.     difference = float('%.2f' % difference)
58.     for price in moneyTypes.values():
59.         if difference >= price:
60.             validTypes.append(price)
61.     validTypes.sort(reverse = True)
62.     for item in validTypes:
63.         item = Decimal(item)
64.     formattedValidTypes = ['%.2f' % price for price in validTypes]
65.     for item in formattedValidTypes:
66.         item = float(item)     #this is not converting correctly
67.     print(validTypes)
68.
69.     for price in formattedValidTypes:
70.         print(difference)
71.         print(type(difference))
72.         print(type(price))
73.         howManyType = math.floor(difference/price)
74.         amountTypes[list(moneyTypes.keys())[list(moneyTypes.values()).index(price)]] = howManyType  #issue here
75.         difference = difference - howManyType*int(price)
76.         difference = float('%.2f' % difference)
77.         print(difference)
78.         if difference == 0:
79.             break
80.
81.     print("Your change will be: \n")
82.     for k, v in amountTypes.items():
83.         print(f"{k}: {v}")"""
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.

Top