[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)
相關文章
相關標籤/搜索