Advertisement
Guest User

Tax Bill calculator in Python

a guest
Dec 16th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. '''
  2. Tax calc for CA residents. Does not include property tax, child credits etc.
  3. '''
  4.  
  5. SLABS = [
  6. (10, 9525, 19050),
  7. (12, 38700, 77400),
  8. (22, 82500, 165000),
  9. (24, 157500, 315000),
  10. (32, 200000, 400000),
  11. (35, 500000, 600000)]
  12.  
  13. CASLABS = [
  14. (1, 7850, 15700),
  15. (2, 18610, 37220),
  16. (4, 29372, 58744),
  17. (6, 40773, 81546),
  18. (8, 51530, 103060),
  19. (9.30, 263222, 526444),
  20. (10.3, 315866, 631732),
  21. (11.3, 526443, 1052886),
  22. ]
  23.  
  24. def fica(inc):
  25.     tax = min(inc, 127200.) * 6.2 / 100.
  26.     tax += min(inc, 200000) * 1.45/100.
  27.     if inc > 200000:
  28.         tax += (inc - 200000) * 2.35/100.
  29.     return tax
  30.    
  31. def _calc(inc, slabs, highest):
  32.     tax = 0.
  33.     for rate, limit in slabs:
  34.         if inc > limit:
  35.             tax += rate * limit / 100.
  36.             inc -= limit
  37.         else:
  38.             tax += rate * inc / 100.
  39.             inc = 0.
  40.     if inc > 0:
  41.         tax += highest * inc / 100.
  42.     return tax
  43.  
  44.  
  45. def calc(inc, issingle):
  46.     if issingle:
  47.         state = _calc(inc - 3992, [(e[0], e[1]) for e in CASLABS], 12.3)
  48.         ded = min(10000, state)
  49.         return fica(inc) + state + _calc(inc - 12000 - ded, [(e[0], e[1]) for e in SLABS], 37.)
  50.     else:
  51.         state = _calc(inc - 7984, [(e[0], e[2]) for e in CASLABS], 12.3)
  52.         ded = min(10000, state)
  53.         return fica(inc) + state + _calc(inc - 24000, [(e[0], e[2]) for e in SLABS], 37.)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement