Skip to content

Instantly share code, notes, and snippets.

@msukmanowsky
Created December 3, 2017 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msukmanowsky/aa7670b2209a1b816bc0393fc993689d to your computer and use it in GitHub Desktop.
Save msukmanowsky/aa7670b2209a1b816bc0393fc993689d to your computer and use it in GitHub Desktop.
def marginal_tax_calculator(brackets):
def calculate(amount):
if amount <= 0: return 0
tax = floor = 0
ceil = rate = None
for bracket in brackets:
if len(bracket) == 1:
ceil = float('inf')
rate = bracket[0]
if len(bracket) == 2:
ceil, rate = bracket
if (amount > floor) and (amount <= ceil):
tax += ((amount - floor) * rate)
elif (amount > ceil):
tax += ((ceil - floor) * rate)
floor = ceil
return tax
return calculate
ontario_ltt = marginal_tax_calculator([
[55000, 0.005],
[250000, 0.01],
[400000, 0.015],
[2000000, 0.02],
[0.025]
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment