Created
December 3, 2017 19:01
-
-
Save msukmanowsky/aa7670b2209a1b816bc0393fc993689d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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