请用Python编写一个个税计算器,用户输入为应发工资薪金所得扣除五险一金后的金额输出应缴税款,核实发工资结果,保留小数点后两位,当输入数字小于零时 输出error
时间: 2024-12-14 10:21:40 浏览: 15
当然可以。下面是一个简单的Python程序,用于计算个人所得税。这个程序假设税率表如下:
- 免征额:5000元
- 税率分为7级,逐级累进
```python
def calculate_tax(income_after_deductions):
if income_after_deductions < 0:
return "error"
tax_free = 5000
tax_rates = [
(0, 0),
(3000, 3),
(12000, 10),
(25000, 20),
(35000, 25),
(55000, 30),
(80000, 35),
(160000, 45)
]
for threshold, rate in tax_rates:
if income_after_deductions <= threshold:
tax = (income_after_deductions - tax_free) * rate / 100
break
# 四舍五入到两位小数
tax = round(tax, 2)
return tax
# 用户输入
income_input = float(input("请输入扣除五险一金后的工资金额(元): "))
tax_result = calculate_tax(income_input)
if isinstance(tax_result, str):
print(tax_result)
else:
print(f"应缴税款: {tax_result} 元")
```
用户运行此程序,按照提示输入应发工资薪金所得扣除五险一金后的金额即可得到相应税务信息。
阅读全文