码迷,mamicode.com
首页 > 编程语言 > 详细

[python 练习] 计算个税

时间:2018-11-05 16:15:50      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:python 练习   +=   ati   div   ons   ict   计算   rom   coding   

题目:利用python计算个税

说明:python有序字典的使用

代码:

 1 # -*- coding: utf-8 -*-
 2 
 3 from collections import OrderedDict
 4 
 5 # 税率表, 2018.10新个税
 6 tax_ratio = OrderedDict()
 7 tax_ratio[(0, 5000)] = 0
 8 tax_ratio[(5000, 3000)] = 0.03
 9 tax_ratio[(3000, 12000)] = 0.1
10 tax_ratio[(12000, 25000)] = 0.2
11 tax_ratio[(25000, 35000)] = 0.25
12 tax_ratio[(35000, 55000)] = 0.3
13 tax_ratio[(55000, 80000)] = 0.35
14 tax_ratio[(80000, float(inf))] = 0.45
15 
16 
17 # 计算税
18 def tax(income, social_benefits=0):
19     income -= social_benefits
20     total_tax = 0
21     for k, v in tax_ratio.items():
22         if income > k[1]:
23             income -= k[1]
24             total_tax += k[1] * v
25         elif k[0] < income < k[1]:
26             total_tax += income * v
27             break
28     return total_tax
29 
30 
31 if __name__ == __main__:
32     print(tax(12705))
33     print(tax(15000, 2295))
34     print(tax(income=15000, social_benefits=2295))
35     print(tax(social_benefits=2295, income=15000))

 

[python 练习] 计算个税

标签:python 练习   +=   ati   div   ons   ict   计算   rom   coding   

原文地址:https://www.cnblogs.com/coder211/p/9909385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!