用 python写我国的个人所得税计算方法
时间: 2023-05-14 11:06:06 浏览: 263
个人所得税的计算方法
5星 · 资源好评率100%
以下是用 Python 编写的个人所得税计算方法:
```python
def calculate_personal_income_tax(income):
"""
计算个人所得税
:param income: 税前收入
:return: 应缴纳的个人所得税
"""
# 免征额
threshold = 5000
# 应纳税所得额
taxable_income = income - threshold
# 税率和速算扣除数
tax_rates = [
(36000, 0.03, 0),
(144000, 0.1, 2520),
(300000, 0.2, 16920),
(420000, 0.25, 31920),
(660000, 0.3, 52920),
(960000, 0.35, 85920),
(float('inf'), 0.45, 181920)
]
# 累计应纳税额
total_tax = 0
for level in tax_rates:
if taxable_income <= 0:
break
level_income, tax_rate, quick_deduction = level
if taxable_income > level_income:
taxable = level_income
else:
taxable = taxable_income
tax = taxable * tax_rate - quick_deduction
total_tax += tax
taxable_income -= level_income
return total_tax
```
使用方法:
```python
income = 10000 # 税前收入
tax = calculate_personal_income_tax(income)
print(f"税前收入为 {income} 元时,应缴纳个人所得税 {tax:.2f} 元")
```
输出结果:
```
税前收入为 10000 元时,应缴纳个人所得税 45.00 元
```
注意:此代码仅供参考,实际应用中还需要考虑各种特殊情况和政策变化。
阅读全文