Spaces:
Sleeping
Sleeping
File size: 504 Bytes
e450bc0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def calculate_tax(income, tax_brackets):
"""Calculate tax using progressive brackets."""
tax = 0
previous_limit = 0
for bracket in sorted(tax_brackets, key=lambda x: x["limit"]):
if income > bracket["limit"]:
taxable_amount = bracket["limit"] - previous_limit
tax += taxable_amount * bracket["rate"]
previous_limit = bracket["limit"]
else:
tax += (income - previous_limit) * bracket["rate"]
break
return tax |