fork(1) download
  1. def printCoins(amntForWhichChangeIsToBeFound,LastcoinUsedToGetChangeArray):
  2. coin = amntForWhichChangeIsToBeFound
  3. while coin > 0:
  4. LastCoinForCoinCent = LastcoinUsedToGetChangeArray[coin]
  5. print(LastCoinForCoinCent)
  6. coin = coin - LastCoinForCoinCent
  7.  
  8. def main():
  9. amntForWhichChangeIsToBeFound = 68
  10. #edit it for the value you want it for
  11. coinsWeHaveUsingwhichChangeHastoBeFound = [1,5,10,21,25]
  12. LastcoinUsedToGetChangeArray = [0]*(amntForWhichChangeIsToBeFound+1)
  13. numberOfCoinsUsedForChange = [0]*(amntForWhichChangeIsToBeFound+1)
  14. for cents in range(amntForWhichChangeIsToBeFound+1):
  15. #This loop starts finding change from 1 cent, then 2,3,4..amntForWhichChangeIsToBeFound
  16. coinCount = cents
  17. LastCoinUsedforChange = 1
  18. for j in [c for c in coinsWeHaveUsingwhichChangeHastoBeFound if c <= cents]:
  19. if numberOfCoinsUsedForChange[cents - j] + 1 < coinCount:
  20. coinCount = numberOfCoinsUsedForChange[cents - j] + 1
  21. LastCoinUsedforChange = j
  22. numberOfCoinsUsedForChange[cents] = coinCount
  23. LastcoinUsedToGetChangeArray[cents] = LastCoinUsedforChange
  24. #print (numberOfCoinsUsedForChange)
  25. #print (LastcoinUsedToGetChangeArray)
  26. print("Number of coins used: "+ str(numberOfCoinsUsedForChange[amntForWhichChangeIsToBeFound]))
  27. print("Here are the coins used ")
  28. printCoins(amntForWhichChangeIsToBeFound, LastcoinUsedToGetChangeArray)
  29.  
  30. main()# your code goes here
Success #stdin #stdout 0.02s 8688KB
stdin
Standard input is empty
stdout
Number of coins used: 4
Here are the coins used 
1
21
21
25