I'm trying to create a sales commission calculator. These are the roles:
Tiers | Amount | Percentage applied
1 | £84,000 - £98,000 | 7.50%
2 | £98,000 - £112,000 | 10.00%
3 | £112,000 - £126,000 | 12%
4 | £126,000- £146,000 | 15.00%
minimum amount= 84k
This is my code, but it doesn't return any value
from bisect import bisect
rates = [0, 7.5, 10, 12, 15]
brackets = [84000, # first 84k
98000, # next 14k
112000, # next 14k
126000, # next 14k
146000] # next 20k
base_tax = [0, # 84k * 0%
14000, # 14k * 7.5%
14000, # 14k * 7.5% + 14000
14000, # 14k * 7.5% + 14000 + 14000
20000] # 20k * 15% + 14000 + 14000 + 14000
income = 120000
def tax(income):
i = bisect(brackets, income)
if not i:
return 0
rate = rates[i]
bracket = brackets[i-1]
income_in_bracket = income - bracket
tax_in_bracket = income_in_bracket * rate / 100
total_tax = base_tax[i-1] + tax_in_bracket
return total_tax
How can I implement an automatic calculator that takes into account the ratios and the different tires?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…