一、旧税率表与新税率表比较
以前起征点是3500,2018年10月1日起起征点正式修改为5000,下面我们用Python来分别计算新旧个人所得税分别为多少?
二、旧的个人所得税
import sys
import bisect
def old_tax(salary):
if salary < 3500:
return 0.0
above = salary - 3500
ranges = [0,1500,4500,9000,35000,55000,80000]
rate = [0.03,0.1,0.2,0.25,0.30,0.35,0.45]
i = bisect.bisect_left(ranges, above)
j = 0
tax = 0.0
while j < i:
if j+1 < i:
tax += (ranges[j+1]-ranges[j]) * rate[j]
else:
tax += (above - ranges[j]) * rate[j]
j += 1
return tax
三、新的个人所得税
def new_tax(salary):
if salary < 5000:
return 0.0
above = salary - 5000
ranges = [0,3000,12000,25000,35000,55000,80000]
rate = [0.03,0.10,0.20,0.25,0.30,0.35,0.45]
i = bisect.bisect_left(ranges, above)
j = 0
tax = 0.0
while j < i:
if j+1 < i:
tax += (ranges[j+1]-ranges[j]) * rate[j]
else:
tax += (above - ranges[j]) * rate[j]
j += 1
return tax
四、少交多少税?
主函数:
if __name__ == "__main__":
if(len(sys.argv)) < 2:
print("Usage:{} <salary>".format(sys.argv[0]))
sys.exit(1)
salary = float(sys.argv[1])
old_tax = old_tax(salary)
new_tax = new_tax(salary)
print("old:{}, new:{}".format(old_tax, new_tax))
把上述代码保存在tax.py文件中,利用cmd进行打开计算可以得到:
五、其他
1.bisect模块中的bisect_left(L,x)函数可以返回x在L中应该插入的位置;
2.sys.argv可以实现外部传递参数,其中sys.argv[0]是脚本的名字,1,2...则为传递的参数。
END 2018-11-01 23:05:12