PAYE IN KENYA CODE CALCULATOR

def calculate_paye_kenya(gross_salary):

“””

Calculate the PAYE tax for a given gross salary in Kenya.

```
:param gross_salary: The gross monthly salary of the employee.
:return: The PAYE amount after considering the tax bands and personal relief.
"""
# Define the tax bands and rates as per Kenya's tax regulations
tax_bands = [
(24000, 0.1), # 10% for the first KES 24,000
(8333, 0.25), # 25% for the next KES 8,333
(41667, 0.3), # 30% for the next KES 41,667
(float('inf'), 0.3) # 30% for the remaining amount
]
# Standard personal relief as of current tax regulations
personal_relief = 2400 # KES 2,400 per month
# Calculate the PAYE tax
tax_payable = 0
remaining_salary = gross_salary
for band_limit, rate in tax_bands:
if remaining_salary > band_limit:
tax_payable += band_limit * rate
remaining_salary -= band_limit
else:
tax_payable += remaining_salary * rate
break
# Deduct the personal relief
paye = max(0, tax_payable - personal_relief)
return round(paye, 2)
```

def calculate_net_salary(gross_salary, other_deductions):

“””

Calculate the net salary after PAYE and other deductions.

```
:param gross_salary: The gross monthly salary of the employee.
:param other_deductions: A list of additional deductions (e.g., loan repayments, pension contributions).
:return: The net salary after all deductions.
"""
# Calculate PAYE
paye = calculate_paye_kenya(gross_salary)
# Sum of all additional deductions
total_deductions = sum(other_deductions)
# Calculate the net salary
net_salary = gross_salary - paye - total_deductions
return {
"Gross Salary": gross_salary,
"PAYE": paye,
"Other Deductions": total_deductions,
"Net Salary": round(net_salary, 2)
}
```

# Example usage

gross_salary = 50000 # Example gross salary in KES

other_deductions = [5000, 2000] # Example deductions (e.g., loan repayment of 5,000, pension contribution of 2,000)

net_salary_info = calculate_net_salary(gross_salary, other_deductions)

# Print the salary breakdown

for key, value in net_salary_info.items():

print(f”{key}: KES {value}”)