易学笔记-python计算个人所得税

2018年10月1号开始执行最新费率的个人所得税,这里用python实现个人所得税的计算:

易学笔记-python计算个人所得税_第1张图片

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> def persontax(totalMoney):
         resultMoney = 0
         if totalMoney <= 5000:
                   return resultMoney
         
         #金额区间
         taxMoney= ((0,3000),(3000,12000),(12000,25000),(25000,35000),(35000,55000),(55000,80000),(80000,1000000000))
         #费率元组
         taxRate = (0.03,0.1,0.2,0.25,0.3,0.35,0.45)
         #扣除元组
         deductMoney = (0,210,1410,2660,4410,7160,15160)
         
         #剩余金额
         subMoney = totalMoney - 5000
         
         #遍历金额区间
         index = -1
         for i in range(len(taxMoney)):
            if taxMoney[i][0] <= subMoney <= taxMoney[i][1]:
                    index = i
                    break
         
         if index >= 0 :
                   resultMoney = subMoney * taxRate[index] - deductMoney[index]
         
         return resultMoney

>>> persontax(10000.00)
290.0
>>> 

笔记式视频学习序列:Python/GO/JAVA序列/容器/微服务详细讲解课程

你可能感兴趣的:(python语言)