如何用Python根据个人所得税计算年收入其中免征额固定为60000元,各项附加扣除固定为18000
作者:野牛程序员:2024-01-05 11:21:36python阅读 2517
如何用Python根据个人所得税计算年收入其中免征额固定为60000元,各项附加扣除固定为18000
方法1:
def caltax(shouru): mtax = 60000 # 免征额 addit = 18000 # 附加扣除 shiji = shouru - mtax - addit # 计算税额 if shiji <= 36000: tax_amount = shiji * 0.03 elif 36000 < shiji <= 144000: tax_amount = 36000 * 0.03 + (shiji - 36000) * 0.1 elif 144000 < shiji <= 300000: tax_amount = 36000 * 0.03 + (144000 - 36000) * 0.1 + (shiji - 144000) * 0.2 elif 300000 < shiji <= 420000: tax_amount = 36000 * 0.03 + (144000 - 36000) * 0.1 + (300000 - 144000) * 0.2 + (shiji - 300000) * 0.25 elif 420000 < shiji <= 660000: tax_amount = 36000 * 0.03 + (144000 - 36000) * 0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (shiji - 420000) * 0.3 elif 660000 < shiji <= 960000: tax_amount = 36000 * 0.03 + (144000 - 36000) * 0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (660000 - 420000) * 0.3 + (shiji - 660000) * 0.35 else: tax_amount = 36000 * 0.03 + (144000 - 36000) * 0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (660000 - 420000) * 0.3 + (960000 - 660000) * 0.35 + (shiji - 960000) * 0.45 return max(0, tax_amount) # 示例用法 shouru = int(input("请输入年收入")) taxsj = caltax(shouru) print("年收入:{}元,应缴个人所得税:{}元".format(shouru, taxsj))
方法2:
def caltax(shouru): mtax = 60000 # 免征额 addit = 18000 # 附加扣除 shiji = shouru - mtax - addit # 税率表 taxtable = [(0, 36000, 0.03), (36000, 144000, 0.1), (144000, 300000, 0.2), (300000, 420000, 0.25), (420000, 660000, 0.3), (660000, 960000, 0.35), (960000, float('inf'), 0.45)] # 计算税额 tax_amount = 0 for lower, upper, rate in taxtable: if shiji <= lower: break elif lower < shiji <= upper: tax_amount += (shiji - lower) * rate break else: tax_amount += (upper - lower) * rate return max(0, tax_amount) # 示例用法 shouru=int(input("请输入年收入")) taxsj = caltax(shouru) print("年收入:{}元,应缴个人所得税:{}元".format(shouru, taxsj))
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892