错字不可订阅

时间:2015-11-02 19:53:24

标签: python object int subscript

我正在尝试计算这个计算器的应税收入,并且我一直收到错误消息"拼写错误是不可订阅的。"该错误出现在calcPEP函数中。我试图将AGI从我的TaxReturn对象传递到我的计算器中来计算豁免的淘汰量,然后计算应税收入。

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))

2 个答案:

答案 0 :(得分:1)

可能会更多,但我确实在那里看到math.ceil(PEP_amount) = PEP_amount。您需要在此处交换左侧和右侧,因为您无法为函数调用分配值,如错误消息所示。

答案 1 :(得分:1)

语法错误上方的行显示问题行;

math.ceil(PEP_amount) = PEP_amount

你不能为一个函数调用分配一个值,我的猜测是你倒退了:

PEP_amount = math.ceil(PEP_amount)