用 Python 写个2019年专项扣除新个人所得税计算器

2019年1月1日起,全新的带专项扣除额的个税开始实施了。
这无疑是个好消息!
不论你的税前工资是三线城市的三五千元,
还是月薪过万的白领,
亦或是动辄几十万年薪的码农。

可是2019新个税的计算方法与以往都不一样,每个月的扣税额都不一样,很让人头疼。
本着练习的目的和钻牛角尖的”精神“,拖着感冒的浑身无力的身体,
对抗了理清其中复杂逻辑的头疼感,2 小时(有点慢),总算是搞出来了。
很简单的语法,可能不是最漂亮的写法,还请对于我这样的新手多予以鼓励吧!
当然,本人还是虚心的,十分渴望大神的不吝赐教!

全部代码如下:
PS:

  1. 执行脚本后,根据提示输入相关数据(税前工资、五险、一金、专项扣除总额)即可;
  2. 脚本为 Python 2.x
  3. 本脚本不适用以下情况:
    a)每月工资不固定的;
    b)专项扣除不是从1月份开始贯穿全年的;
    c)年底奖金税额不计算在其中
    d)仅供学习交流参考之用
  4. 转载还请注明出处!
# coding:utf-8


def tax_basic_value():
    salary_before = input('输入您的税前薪资:')
    insurance_amount = input('输入您的保险扣除总额:')
    housing_fund = input('输入您的住房公积金扣除额:')
    special_deduction_total = input('输入您的各项专项扣除总额:')

    tax_basic_value = salary_before - insurance_amount - housing_fund - special_deduction_total - 5000

    return tax_basic_value


def tax_yearly(tax_basic_value):
    tax_all = []
    for i in range(1, 13):
        tax_basic_year = tax_basic_value * i
        if 0 < tax_basic_year <= 36000:
            tax_mid = tax_basic_year * 0.03
        elif 36000 < tax_basic_year <= 144000:
            tax_mid = tax_basic_year * 0.10 - 2520
        elif 144000 < tax_basic_year <= 300000:
            tax_mid = tax_basic_year * 0.20 - 16920
        elif 300000 < tax_basic_year <= 420000:
            tax_mid = tax_basic_year * 0.25 - 31920
        elif 420000 < tax_basic_year <= 660000:
            tax_mid = tax_basic_year * 0.30 - 52920
        elif 660000 < tax_basic_year <= 960000:
            tax_mid = tax_basic_year * 0.35 - 85920
        elif tax_basic_year > 960000:
            tax_mid = tax_basic_year * 0.45 - 181920
        else:
            tax_mid = 0

        tax_all.append(tax_mid)

    tax_yearly = []
    for i in range(len(tax_all)):
        if i == 0:
            tax_monthly = tax_all[0]
        else:
            tax_monthly = tax_all[i] - tax_all[i - 1]

        tax_yearly.append(tax_monthly)
        print 'Month %s: %s' % ((i + 1), tax_monthly)

    return tax_yearly


def tax_total(tax_yearly):
    tax_total = 0
    for i in tax_yearly:
        tax_total += i
    print '\nYearly Total Tax: %s' % tax_total

    everage_monthy_tax = tax_total / 12.00
    print 'The Everage Monthly Tax: %s' % everage_monthy_tax

    minus_2018 = tax_total - tax_total_2018
    minus_2018 = '%.2f' % minus_2018

    if float(minus_2018) < 0:
        minus_2018_abs = abs(float(minus_2018))
        print 'Compared to 2018, Yearly Saved Tax is: %s' % minus_2018_abs
    else:
        print 'Compared to 2018, Yearly Increased Tax is: %s' % minus_2018


if __name__ == '__main__':
    tax_basic_value = tax_basic_value()
    tax_yearly = tax_yearly(tax_basic_value)

    # Year 2018 Total Tax.
    tax_monthly_2018 = input('\n输入您的2018年每月个税额:')
    tax_total_2018 = tax_monthly_2018 * 12
    print '2018 Yearly Total Tax is: %s' % tax_total_2018

    tax_total(tax_yearly)

执行效果(以税前收入 2 万元为例):

Screen Shot 2018-12-29 at 3.18.45 PM.png

每月个税减少 300 元,还是不少的。

你可能感兴趣的:(用 Python 写个2019年专项扣除新个人所得税计算器)