0

I am trying to calculate taxable income from this calculator, and I keep receiving the error message "typo is not subscriptable." The error appears in the calcPEP function. I am trying to pass AGI from my TaxReturn Object into my calculator to calculate the phaseout of exemptions, and subsequently calculate taxable income.

class TaxReturn:
    def __init__(self, AGI):
        self.AGI = AGI

#import math program to retrieve rounding function
import math
#assign name to TaxReturn class
txreturn = TaxReturn()
#class for pesonal exemption phaseout (PEP)
class PEP:
#define phase in rate, personal exemption amount, AGI phaseout thresholds
    def __init__(self, phase_in_rate, personal_exemption, dependents):

        self.phase_in_rate = phase_in_rate
        self.personal_exemption = personal_exemption
        self.dependents = dependents

    #calculate PEP using AGI attribute from TaxReturn object
    def calcPEP (phase_in_rate, personal_exemption, dependents, txreturn):  
        #thresholds by filer status  where PEP  phase-outs begin
        #[single, HOH, married joint, married separate]
        phase_out_threshold = int[258250, 284050, 309900, 154950]
        for i in phase_out_threshold:   
            if txreturn.AGI >= phase_out_threshold:    
                #calculate the amount to which PEP applies                      
                PEP_amount = txreturn.AGI - i
                #calculate PEP multiplier
                PEP_amount /= 2500
                #round up PEP multplier
                PEP_amount = math.ceil(PEP_amount)              
                PEP_amount = (PEP_amount*phase_in_rate)/100
                #calculate total reduction of exemptions
                PEP_amount *= personal_exemption*dependents
                #calculate taxable income
                if personal_exemption*dependents - PEP_amount > 0:
                    taxable_inc = txreturn.AGI - (personal_exemption*dependents - PEP_amount)                    
                else: 
                    taxable_inc = txreturn.AGI

            else: taxable_inc = txreturn.AGI - personal_exemption*dependents

            return taxable_inc

testPEP = PEP(2, 4000, 2)
print(testPEP.calcPEP(4000, 2, 350000))
Alex Durante
  • 71
  • 2
  • 7

2 Answers2

1

Might be more, but I do see math.ceil(PEP_amount) = PEP_amount in there. You need to swap the left and right hand sides here since you can't assign a value to a function call, as the error message states.

Randy
  • 14,349
  • 2
  • 36
  • 42
1

The line above the syntax error shows you the problem line;

math.ceil(PEP_amount) = PEP_amount

You can't assign a value to a function call, my guess is you have it backwards:

PEP_amount = math.ceil(PEP_amount) 
AlG
  • 14,697
  • 4
  • 41
  • 54