根据累进税率计算每月个人所得税 python代码

使用时将工资、社保和公积金替换即可,累进税率表和起征点根据所在当地调整

import numpy as np

# 累进税率表:交税比例及速算扣除数
tax_rates = {
    36000: {"tax_rate": 0.03, "quick_deduction": 0},
    144000: {"tax_rate": 0.1, "quick_deduction": 2520},
    300000: {"tax_rate": 0.2, "quick_deduction": 16920},
    420000: {"tax_rate": 0.25, "quick_deduction": 31920},
    660000: {"tax_rate": 0.3, "quick_deduction": 52920},
    960000: {"tax_rate": 0.35, "quick_deduction": 85920},
    float("inf"): {"tax_rate": 0.45, "quick_deduction": 181920},
}

# 起征点
tax_free = 5000

# 工资:12个月单独写,如果不变也可用以下注释
# salaries = [10000 for i in range(12)]
salaries = [
    0,
    0,
    10000,
    10000,
    10000,
    10000,
    10000,
    10000,
    10000,
    10000,
    10000,
    10000,
]
# 社保&公积金
endowment_fund = 200
public_accumulation_funds = 100


salaries = np.array(
    [i - endowment_fund - public_accumulation_funds for i in salaries if i > 0]
)

sum_paid_tax = 0
for month in range(len(salaries)):
    this_salary = salaries[month]
    sum_need_to_tax = salaries[: month + 1].sum() - (month + 1) * tax_free
    for key, v in tax_rates.items():
        if sum_need_to_tax <= key and sum_need_to_tax > 0:
            tax = sum_need_to_tax * v["tax_rate"] - v["quick_deduction"] - sum_paid_tax
            sum_paid_tax += tax
            print(
                "month:",
                month + 1,
                "tax:",
                round(tax, 2),
                "salaries:",
                round(this_salary - tax, 2),
            )
            break

print("Total tax this year:", round(sum_paid_tax, 2))
posted @   微风林林  阅读(65)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示