在Python中使用词典,For-Loops和Brackets

时间:2015-11-16 19:58:46

标签: python for-loop dictionary brackets

我需要帮助创建字典。字典的目的是计算税收抵免的大小。有八个时间表,每个有三个括号。您可以根据申请状态和符合条件的子女数量选择时间表。在第一个范围内,信贷将按收入的百分比分阶段进行。在第二个括号中,信用额度最大化。在第三个方面,信贷开始逐步取消,占收入的百分比。问题是我不确定如何构建计算器以产生这些结果,或者甚至可能。我怀疑需要三个if语句,每个括号一个。以下是我到目前为止的情况:

#import TaxReturn class
from TaxReturn import TaxReturn

#create brackets for phasein rates and phaseout rates for the earned income tax credit (EITC)
class EITC:
   def __init__(self, taxReturn):     
       self.brackets = {
           "single" and taxReturn.eic_qualify_children == 0 : ((0, .0765), (6480, .0765), (8110, .0765)),
           "single" and taxReturn.eic_qualify_children == 1 : ((0, .34), (9720, .34), (17830, .1598)),
           "single" and taxReturn.eic_qualify_children == 2 : ((0, .40), (13650, .40), (17830, .2106)),
           "single" and taxReturn.eic_qualify_children > 2 : ((0, .45), (13650, .45), (17830, .2106)),
           "married_jointly" and taxReturn.eic_qualify_children == 0 : ((0, .0765), (6480, .0765), (13540, .0765)),
           "married_jointly" and taxReturn.eic_qualify_children == 1 : ((0, .34), (9720, .34), (23260, .1598)),
           "married_jointly" and taxReturn.eic_qualify_children == 2 : ((0, .40), (13650, .40), (23260, .2106)),
           "married_jointly" and taxReturn.eic_qualify_children > 2 : ((0, .45), (13650, .45), (23260, .2106))
       }

#calculate EITC credit
   def CalcEITC (self, taxReturn):
      eitc_credit = 0
      for bracket in reversed(self.brackets[taxReturn.taxComp.filing_status and taxReturn.eic_qualify_children]):
          if taxReturn.taxPayments.earned_inc > bracket[0]:
              eitc_credit += (taxReturn.taxPayments.earned_inc - bracket[0]) * bracket[1]
              taxReturn.taxPayments.earned_inc -= taxReturn.taxPayments.earned_inc - bracket[0]

0 个答案:

没有答案