Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10. Suppose that a cashier owes a customer some change and that the cashier only

ID: 670187 • Letter: 1

Question

10. Suppose that a cashier owes a customer some change and that the cashier only has quarters, dimes, nickels, and pennies. Write a function that computes the minimum number of coins that the cashier can return. In particular, write a function change_to_coins(amount) that returns the minimum possible number of coints that add up to the given amount of dollars.  You may assume that the input to function change_to_coins(amount)is a float value referred to by amount representing the number of dollars. Before doing anything else, you should convert this number entirely to cents (that should be of type int). Once you have the total number of cents here are some hints on how to find the minimum number of coins. (it's a python program)

Explanation / Answer

def Currency(w):
  
if w==0:
return 0
if w%25==0:
return (w/25)
else:
c=int(w/25)
r=w%25
  
if r%10==0:
return (c+r/10)
else:
c=c+int(r/10)
r=r%10
  
if r%5==0:
return (c+r/5)
else :
c=c+int(r/5)
r=r%5
c=c+r
return c


w=float(raw_input("Enter the amount: "))
w=100.0*w
t=Currency(w)
print "Minimum coins",t