0

私は宿題のためにこれに取り組んでおり、これのほとんどを完了しました。私の問題は、50,000 の範囲内のすべての値の行である必要があるときに、表示が 1 行だけであるため、for ループの 1 つに何か問題があることです。 - ステップ値 50 で 60,000。

    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 に答える