Spaces:
Sleeping
Sleeping
| 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 |