Matt23

Salary payment algorithm

Dec 19th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import math
  2.  
  3. salaries = [4352, 4536, 3224, 7686, 1243, 659, 633, 1324, 1254, 1678, 1160]
  4. payments = [[0 for x in range(9)] for x in range(len(salaries))]
  5. banknotes = [200, 100, 50, 20, 10, 5, 2, 1]
  6.  
  7. def doJob(i, salary):
  8.     for j, banknote in enumerate(banknotes):
  9.         if salary >= banknote:
  10.             payments[i][j + 1] = int(math.floor(salary / banknote))
  11.             salary = salary % banknote
  12.  
  13. for i, salary in enumerate(salaries):
  14.     payments[i][0] = salary
  15.     doJob(i, salary)
  16.  
  17. toPrint = ""
  18. for payment in payments:
  19.     toPrint += str(payment[0]) + ": "
  20.     for i, value in enumerate(payment[1:]):
  21.         if value is not 0:
  22.             toPrint += "{0} x{1}, ".format(banknotes[i], value)
  23.     toPrint += '\n'
  24. print(toPrint)
Advertisement
Add Comment
Please, Sign In to add comment