-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_calculator.py
More file actions
29 lines (26 loc) · 1.01 KB
/
Copy pathchange_calculator.py
File metadata and controls
29 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def change():
while True:
allchange={"quarters":0,"dimes":0,"nickels":0,"pennies":0}
changeval={"quarters":0.25,"dimes":0.10,"nickels":0.05,"pennies":0.01}
#total=float(input("How much change required? "))
try:
price,money=input("Enter price, then cash received: ").split()
price=float(price)
money=float(money)
total=money-price
if (total < 0.0):
print("Not enough cash!!")
continue
for key,val in sorted(allchange.items(), key=lambda x: x[1],reverse=True):
allchange[key]=int((100.*total)//(100.*changeval[key]))
total=0.01*round((100.*total)%(100.*changeval[key]))
print(allchange)
except:
print("Wrong number of inputs")
qq=input("Quit program? y/n: ")
if (qq.lower() in ["y","yes"]):
exit()
else:
continue
if __name__ == '__main__':
change()