2013-02-28 78 views
0

我在與我的這部分代碼的問題:
蟒蛇 - 打破嵌套條件的原始圈頂部

if(input not in status_list): 
    print("Invalid Entry, try again.") 
    break 

斷裂退出整個程序,我只是想回去程序(至的開始,而(1):)
我試圖通,繼續回想不出別的..誰能幫助? 謝謝:)
此外它閱讀本浮動收入爲字符串仍然..:income = int(input("Enter taxable income: "))該錯誤消息我得到的是「類型錯誤:‘海峽’對象不是可調用的」

import subprocess 
status_list = ["s","mj","ms","h"] 


while(1): 
    print ("\nCompute income tax: \n") 
    print ("Status' are formatted as: ") 
    print ("s = single \n mj = married and filing jointly \n ms = married and filing seperately \n h = head of household \n q = quit\n") 
    input = input("Enter status: ") 
    if(input == 'q'): 
     print("Quitting program.") 
     break 
    if(input not in status_list): 
     print("Invalid Entry, try again.") 
     break 

    income = int(input("Enter taxable income: ")) 
    income.replace("$","") 
    income.replace(",","") 

    #passing input to perl files 
    if(input == 's'): 
     subprocess.call("single.pl") 
    elif(input == 'mj'): 
     subprocess.call("mj.pl", income) 
    elif(input == 'ms'): 
     subprocess.call("ms.pl", income) 
    else: 
     subprocess.call("head.pl", income) 
+1

風格上,應避免周圍的條件括號你的'if's和'while's(即'while 1:'而不是'while(1):','如果輸入=='s':'而不是'if(input =='s') :'......) – nneonneo 2013-02-28 20:14:27

+0

'continue'應該按照你想要的來做。 – 2013-02-28 20:15:42

+1

很難理解'繼續'是如何失敗的 – cnicutar 2013-02-28 20:15:45

回答

2
input = input("Enter status: ") 

你從input功能到其結果是,它是一個字符串重新綁定名稱input。所以,下次你怎麼稱呼它,continue後時間不工作,input沒有任何名稱的功能更多,它只是一個字符串,你不能叫一個字符串,因此

TypeError: 'str' object is not callable 

使用continue,和改變你的變量名稱,以免破壞函數。

+0

謝謝,解決了它! – Gcap 2013-02-28 22:54:16

0

您的問題無法繼續,那就是你有一個未解決的錯誤代碼中的進一步下跌。繼續是做什麼它應該(也就是你要在有條件的continue)。

您將input重命名爲字符串,因此該名稱不再指向代碼中內置的input函數。這就是爲什麼你不使用保留關鍵字作爲變量名。調用你的變量而不是「輸入」,你的代碼應該可以正常工作。

0

繼續正常工作。用你的腳本的問題是,你要調用替換()在一個int:

income = int(input("Enter taxable income: ")) 
# income is an int, not a string, so the following fails 
income.replace("$","") 

你可以做這樣的事情,而不是:

income = int(input("Enter taxable income: ").replace("$", "").replace(",", ""))