[Python] 年终奖税后计算器

去年年终奖比前年涨了一些,但实际到手反而少了,当时只知道是由于税率提了一档致使的,但没有深究为何spa

最近研究了一下,发现这就是著名的年终奖一元陷阱code

年终奖的税率计算是,先把年终奖平分到12个月,根据我的所得税税率表找到对应的税率blog

因而年终奖扣税 = 年终奖×对应税率 - 速算扣除数input

若是年终奖多了1块钱,进入下一档税率,根据跨度,会多扣5到15个点,但对应的速扣数没有增长12倍,就致使了年终奖多发一元,实际到手少不少的年终奖一元陷阱class

 

 

 

举例说明,假如13薪和年终奖一块儿发,两个加一块儿算总年终奖。float

好比13薪是10000,年终奖44000,总年终奖是54000,得出54000/12 = 1500, 查表得出用10%那档税率, 实际到手 = 54000 - (54000 × 10% - 105) = 48705im

假如年终奖涨了1000,总年终奖变成55000,55000/12 = 4583, 查表得出用20% 那档税率, 实际到手 = 55000 - (55000 × 20% - 555) =44555img

税率档从10%升到20%,因此虽然总年终奖多了1000,但扣的税多了5150,致使实际到手反而少了4150di

 

代码以下co

def taxRate(bonus,thirteen_month_salary): total = bonus + thirteen_month_salary base = total/12

    if base < 0: bonus_tax = 0 if base <= 1500: bonus_tax = total * 0.03
    elif base > 1500 and base <= 4500: bonus_tax = total * 0.1 - 105
    elif base > 4500 and base <= 9000: bonus_tax = total * 0.2 - 555
    elif base > 9000 and base <= 35000: bonus_tax = total * 0.25 - 1005
    elif base > 35000 and base <= 55000: bonus_tax = total * 0.3 - 2755
    elif base > 55000 and base <= 80000: bonus_tax = total * 0.35 - 5505
    elif base > 80000: bonus_tax = total * 0.45 - 13505

    print('Bonus tax payable is : %d' % bonus_tax) return bonus_tax def BonusAfterTax(bonus, thirteen_month_salary): # 纳税额
    tax = taxRate(bonus,thirteen_month_salary) # 税后bonus
    bonus_after_tax = bonus + thirteen_month_salary - tax print('Bonus after tax is : %d' % bonus_after_tax) print('bonus_after_tax percentage is : %.2f %%' % float(bonus_after_tax * 100 / (bonus + thirteen_month_salary))) return bonus_after_tax if __name__ == '__main__': bonus_before_tax = int(input('Please input your Bonus before tax:')) thirteen_month_salary = int(input('Please input your 13rd Salary before tax:')) BonusAfterTax(bonus_before_tax, thirteen_month_salary)

 

若是速扣数也能对应增长12倍,年终奖一元陷阱就解决了

一样总年终奖从54000涨到55000,若是速扣数相应增长12倍,得出税后年终奖从49860涨到50660

这样税前年终奖涨1000,实际到手涨800,而不是少4150,这才符合指望

 

期待税法能早点把这个失误改过来

 

 代码以下

def bonusTaxRate(bonus,thirteen_month_salary): total = bonus + thirteen_month_salary base = total/12

    if base < 0: bonus_tax = 0 if base <= 1500: bonus_tax = total * 0.03
    elif base > 1500 and base <= 4500: bonus_tax = total * 0.1 - 105
    elif base > 4500 and base <= 9000: bonus_tax = total * 0.2 - 555
    elif base > 9000 and base <= 35000: bonus_tax = total * 0.25 - 1005
    elif base > 35000 and base <= 55000: bonus_tax = total * 0.3 - 2755
    elif base > 55000 and base <= 80000: bonus_tax = total * 0.35 - 5505
    elif base > 80000: bonus_tax = total * 0.45 - 13505

    print('Bonus tax payable is : %d' % bonus_tax) return bonus_tax def bonusAfterTax(bonus, thirteen_month_salary): # 纳税额
    tax = bonusTaxRate(bonus,thirteen_month_salary) # 税后bonus
    bonus_after_tax = bonus + thirteen_month_salary - tax print('Bonus after tax is : %d' % bonus_after_tax) print('bonus_after_tax percentage is : %.2f %%' % float(bonus_after_tax * 100 / (bonus + thirteen_month_salary))) print('                 ') return bonus_after_tax def newBonusTaxRate(bonus, thirteen_month_salary): total = bonus + thirteen_month_salary base = total / 12
  #速扣数相应增大12倍
    if base < 0: bonus_tax = 0 if base <= 1500: bonus_tax = total * 0.03
    elif base > 1500 and base <= 4500: bonus_tax = total * 0.1 - 105 * 12
    elif base > 4500 and base <= 9000: bonus_tax = total * 0.2 - 555 * 12
    elif base > 9000 and base <= 35000: bonus_tax = total * 0.25 - 1005 * 12
    elif base > 35000 and base <= 55000: bonus_tax = total * 0.3 - 2755 * 12
    elif base > 55000 and base <= 80000: bonus_tax = total * 0.35 - 5505 * 12
    elif base > 80000: bonus_tax = total * 0.45 - 13505 * 12

    print('New bonus tax payable is : %d' % bonus_tax) return bonus_tax def newBonusAfterTax(bonus, thirteen_month_salary): total = bonus + thirteen_month_salary # 纳税额
    new_bonus_tax = newBonusTaxRate(bonus,thirteen_month_salary) # 税后bonus
    bonus_after_tax = total - new_bonus_tax print('New Bonus after tax is : %d' % bonus_after_tax) print('New bonus_after_tax percentage is : %.2f %%' % float(bonus_after_tax * 100 / total)) print('                ') return bonus_after_tax if __name__ == '__main__': bonus_before_tax = int(input('Please input your Bonus before tax:')) thirteen_month_salary = int(input('Please input your 13rd Salary before tax:')) bonusAfterTax(bonus_before_tax, thirteen_month_salary) newBonusAfterTax(bonus_before_tax, thirteen_month_salary)
相关文章
相关标签/搜索