2016-09-28 49 views
0

稅計算器語法錯誤,如果... ELIF ......否則

def computeTax(maritalStatus,userIncome): 
    if maritalStatus == "Single": 
    print("User is single") 
    if userIncome <= 9075: 
     tax = (.10) * (userIncome) 
    elif userIncome <= 36900: 
     tax = 907.50 + ((.15) * (userIncome - 9075)) 
    elif userIncome <= 89350: 
     tax = 5081.25 + ((.25) * (userIncome - 36900)) 
    elif userIncome <= 186350: 
     tax = 18193.75 + ((.28) * (userIncome - 89350)) 
    elif userIncome <= 405100: 
     tax = 45353.75 + ((.33) * (userIncome - 186350)) 
    elif userIncome <= 406750: 
     tax = 117541.25 + ((.35) * (userIncome - (405100) 
    else:           # getting syntax error here 
     tax = 118118.75 + ((.396) * (userIncome - (406750)) 
    return tax 
    else: 
    return "placeholder" 

def main(): 
    maritalStatusMain = input("Please enter your marital status (Single or Married)") 
    userIncomeMain = float(input("Please enter your annual income")) 
    finalTax = computeTax(maritalStatusMain,userIncomeMain) 
    print(finalTax) 
main() 

當我刪除或添加語句的語法錯誤似乎跳來跳去。

+0

你的意思的問題,如果你刪除一個elif語句的語法錯誤不再位於第一個else語句的前面? – sabbahillel

回答

1

在它周圍的行快速瀏覽,顯示丟失的圓括號

... 
    tax = 45353.75 + ((.33) * (userIncome - 186350)) # <- two ending parens 
elif userIncome <= 406750: 
    tax = 117541.25 + ((.35) * (userIncome - (405100) # <- one ending paren, plus extra paren around 405100 
else: 
... 

這可能是所有它,除非拷貝+粘貼到失敗