编写程序,实现个人所得税计算器。用户输入全年综合所得以及各项扣除之和后, 计算出应纳税额和税后收入。请分别编写两个函数完成程序,一个用于查找税率, 一个用于计算应交所得税(设置两个形参:应税所得 和 适用税率 )
时间: 2023-05-28 16:04:03 浏览: 190
个人所得税计算器 用于计算个人所得税
def find_tax_rate(income):
"""
查找税率函数
:param income: 全年综合所得
:return: 适用税率
"""
if income <= 0:
return 0
elif income <= 36000:
return 0.03
elif income <= 144000:
return 0.1
elif income <= 300000:
return 0.2
elif income <= 420000:
return 0.25
elif income <= 660000:
return 0.3
elif income <= 960000:
return 0.35
else:
return 0.45
def calculate_taxable_income(income, deduction):
"""
计算应交所得税和税后收入函数
:param income: 全年综合所得
:param deduction: 各项扣除之和
:return: 应交所得税和税后收入
"""
taxable_income = income - deduction - 5000 # 免征额5000元
tax_rate = find_tax_rate(taxable_income)
tax = taxable_income * tax_rate - 0 # 无税收入减免
after_tax_income = income - tax
return tax, after_tax_income
if __name__ == '__main__':
income = float(input("请输入全年综合所得:"))
deduction = float(input("请输入各项扣除之和:"))
tax, after_tax_income = calculate_taxable_income(income, deduction)
print("应交所得税为:{:.2f}元,税后收入为:{:.2f}元。".format(tax, after_tax_income))
阅读全文