1

I want to pass an attribute of tax return data to a tax calculator I have created. For example, I would like to pass salaries_wages of 100000. Here what I have so far but I can't seem to get it to work:

class TaxReturn:

   def __init__(self, income = None, stat_adj = None, AGI = None):

             income = income or ['salaries_wages', 'interest_received', 'tax_exempt_interest_income', 'dividend_AGI', 'qualified_dividend']
             stat_adj = stat_adj or ['deductible_IRA_payments', 'student_loan_interest_deduc', 'education_expenses', 'tuition_fees_deduc', 
             'self_employ_deduc', 'self_employ_healthinsur_deduc', 'domestic_production_deduc']
             AGI = AGI or 'AGI'

             self.income = 'income'
             self.stat_adj = 'stat_adj'
             self.AGI = 'AGI'
class Income:
    def __init__(self= None, salaries_wages= None, intr_rec= None, txexem_intinc= None, dividend_AGI= None, qualified_dividend= None):    

            salaries_wages = salaries_wages or 'salaries_wages'
            intr_rec = intr_rec or 'intr_rec'
            txexem_intinc = txexem_intinc or 'txexem_intinc'
            dividend_AGI = dividend_AGI or 'dividend_AGI'
            qualified_dividend = qualified_dividend or 'qualified_dividend'

class TaxCal:

   def __init__(self):
      self.brackets = {(0,8025):0.10, (8025,32550):.15, (32550,78850):.25, (78850, 164550):.28, (164550,357700):.33, (357700,371815):.35, (371815, sys.maxsize):.396}     

   def taxcal (self, salaries_wages):
      tax = 0       
      for bracket in self.brackets:
        if salaries_wages > bracket[0]:
          for _ in range(bracket[0], min(salares_wages, bracket[1])):
              tax += self.brackets[bracket]
   return tax

tx =  TaxReturn()
inc = Income()
txcal = TaxCal()
print(tx.inc.txcal.taxcal(100000)), format(round(tx.inc.txcal.taxcal(100000), 2)
4
  • Why tx.inc.txcal.taxcal(100000) ? What makes you think inc is an attribute inside tx or so on? Commented Oct 13, 2015 at 15:48
  • @AnandSKumar Can you please show me where I am mistaken? Thanks. Commented Oct 13, 2015 at 15:50
  • Try simply taxcal(100000) . Commented Oct 13, 2015 at 15:52
  • @AnandSKumar Haha ok I understand. How could I improve this so I can make income in TaxCal an attribute of Income? A simple example would be fine. Thanks. Commented Oct 13, 2015 at 15:54

1 Answer 1

1

Take care of your indentation, and class design. I don't know why you are assigning unknown variables in your class. Unless you make it part of class, it is useless:

import sys

class Income:
    def __init__(self= None, salaries_wages= None, intr_rec= None, txexem_intinc= None, dividend_AGI= None, qualified_dividend= None):    

        self.salaries_wages = salaries_wages or 'salaries_wages'
        self.intr_rec = intr_rec or 'intr_rec'
        self.txexem_intinc = txexem_intinc or 'txexem_intinc'
        self.dividend_AGI = dividend_AGI or 'dividend_AGI'
        self.qualified_dividend = qualified_dividend or 'qualified_dividend'

class TaxCal:

   def __init__(self):
      self.brackets = {(0,8025):0.10, (8025,32550):.15, (32550,78850):.25, (78850, 164550):.28, (164550,357700):.33, (357700,371815):.35, (371815, sys.maxsize):.396}     

   def taxcal (self, inc):
       tax = 0       
       for bracket in self.brackets:
           if inc.salaries_wages and inc.salaries_wages > bracket[0]:
              for _ in range(bracket[0], min(inc.salaries_wages, bracket[1])):
                  tax += self.brackets[bracket]
       return tax

tx =  TaxReturn()
inc = Income(100000)
txcal = TaxCal()
print(txcal.taxcal(inc))
Sign up to request clarification or add additional context in comments.

1 Comment

So let me explain what I am trying to do. I have set defaults because eventually I will be using actual tax data. Right now I just wanted to test the code. It looks like what have is helpful though, so thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.