计算个人所得税python
时间: 2023-11-22 21:49:59 浏览: 93
以下是计算个人所得税的Python代码:
```python
def calculate_tax(income):
# 定义税率表
TaxTable = [(0, 500, 0.05), (500, 2000, 0.10), (2000, 5000, 0.15), (5000, 20000, 0.20), (20000, 40000, 0.25), (40000, 60000, 0.30), (60000, 80000, 0.35), (80000, 100000, 0.40), (100000, 1e10, 0.45)]
# 计算应纳税所得额
taxable_income = income - 3500
# 如果应纳税所得额小于等于0,则不需要缴纳个人所得税
if taxable_income <= 0:
return 0
# 遍历税率表,计算应缴纳的税款
tax = 0
for i in range(len(TaxTable)):
if taxable_income > TaxTable[i][0]:
if taxable_income > TaxTable[i][1]:
tax += (TaxTable[i][1] - TaxTable[i][0]) * TaxTable[i][2]
else:
tax += (taxable_income - TaxTable[i][0]) * TaxTable[i][2]
if i == len(TaxTable) - 1:
break
# 返回应缴纳的个人所得税
return tax
```
使用方法:
```python
income = 10000 # 个人收入
tax = calculate_tax(income) # 计算个人所得税
print("个人所得税:%.2f" % tax) # 输出个人所得税
```
阅读全文