个人所得税计算:用户输入应发工资薪金所得、五险一金金额和个税免征额,输出应缴税款和实发工资, 结果保留小数点后两位。当输入数字小于0 或等于0 时,输出“error”。 实发工资 = 应发工资 - 五险一金 - 个人所得税 用python定义一个函数并写出
时间: 2024-06-12 07:06:19 浏览: 91
代码。
def personal_income_tax(salary, social_security, tax_free):
if salary <= 0 or social_security <= 0:
return "error"
else:
taxable_income = salary - social_security - tax_free
if taxable_income <= 0:
tax = 0
elif taxable_income <= 36000:
tax = taxable_income * 0.03
elif taxable_income <= 144000:
tax = taxable_income * 0.1 - 2520
elif taxable_income <= 300000:
tax = taxable_income * 0.2 - 16920
elif taxable_income <= 420000:
tax = taxable_income * 0.25 - 31920
elif taxable_income <= 660000:
tax = taxable_income * 0.3 - 52920
elif taxable_income <= 960000:
tax = taxable_income * 0.35 - 85920
else:
tax = taxable_income * 0.45 - 181920
actual_salary = salary - social_security - tax
return round(tax, 2), round(actual_salary, 2)
#测试
print(personal_income_tax(20000, 1000, 5000)) # (510.0, 14490.0)
print(personal_income_tax(30000, 2000, 3500)) # (960.0, 25140.0)
print(personal_income_tax(-10000, 2000, 3500)) # "error"
阅读全文