Reputation: 71
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)
Upvotes: 1
Views: 50
Reputation: 8553
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))
Upvotes: 1