使用时将工资、社保和公积金替换即可,累进税率表和起征点根据所在当地调整
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))
标签:10000,python,sum,tax,rate,salaries,累进税,deduction,个人所得税
From: https://www.cnblogs.com/zephyrdhb/p/17861479.html