0

我正在为此做家庭作业,我已经完成了大部分工作- 60,000,步长值为 50。

    def computeTax(status, taxableIncome):
        print("Taxable Income/" + "\t" + "Single/" + "\t" + "Married Joint/" + \
              "\t" + "Married Separate/" + "  " + "Head of Household")
        for taxableIncome in range(50000, 60001, 50):
            for status in range(1, 5, 1):
              if (status == 1):    #tax calculation for single person
                 tax1 = 8350 * .10 + (33950 - 8350) * 0.15 + \
                       (taxableIncome - 33950) * 0.25
                 tax1 = round(tax1,0)
              if (status == 2):   #tax calculation for married file jointly
                 tax2 = 16700 * .10 + (67900 - 16700) * 0.15 + \
                        (taxableIncome - 67900) * 0.15
                 tax2 = round(tax2,0)
              if (status == 3):   #tax calculation for married file separately
                 tax3 = 8350 * .10 + (33950 - 8350) * 0.15 + \
                       (taxableIncome - 33950) * 0.25
                 tax3 = round(tax3,0)
              if (status == 4): #tax calculation for head of household
                 tax4 = 11950 * .10 + (45500 - 11950) * 0.15 + \
                       (taxableIncome - 45500) * 0.25
                 tax4 = round(tax4,0)
         print(str(tax1) + "\t" + str(tax2) + "\t" + str(tax3) + "\t" + str(tax4))
        return (status, taxableIncome)


    computeTax(range(1, 5, 1),range(50000, 60001, 50))              
4

1 回答 1

0

我对 python 不熟悉,但是您是否必须像使用 PHP 一样定义代码块?例如

if (status == 1):    #tax calculation for single person
{                 
tax1 = 8350 * .10 + (33950 - 8350) * 0.15 + \
                       (taxableIncome - 33950) * 0.25
                 tax1 = round(tax1,0)
}

就像我说的; 不熟悉Python,但我想我可能会为您提供答案;如果我完全离开了,那么对不起,祝你好运。

于 2012-10-16T22:53:35.250 回答