0

コードのこの部分で問題が発生しています。

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

休憩はプログラム全体を終了します。プログラムの最初に戻りたいだけです(while(1):)
合格、続行、戻りは他に何も考えられません。誰か助けてくれませんか?ありがとう:)
また、この変数の収入を文字列としてまだ読み取っています..:income = int(input("Enter taxable income: "))私が受け取るエラーメッセージは「TypeError:'str'オブジェクトは呼び出し可能ではありません」です

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

3 に答える 3

2
input = input("Enter status: ")

関数の名前inputを、文字列である結果に再バインドします。inputしたがって、次に呼び出すときcontinueは、その作業を行った後input、関数に名前を付けなくなります。これは単なる文字列であり、文字列を呼び出すことはできません。したがって、

TypeError: 'str' object is not callable 

を使用continueし、関数を壊さないように変数名を変更します。

于 2013-02-28T20:17:25.943 に答える
0

続行は正しく機能しています。スクリプトの問題は、intでreplace()を呼び出そうとしていることです。

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(",", ""))
于 2013-02-28T20:32:22.193 に答える
0

あなたの問題は続きません。コードのさらに下に未解決のエラーがあるということです。Continue は、本来あるべきことを正確に実行しています (つまりcontinue、その条件で必要です)。

文字列として名前を変更inputしているため、名前はコード内の組み込み関数を指しなくなりinputます。これが、予約済みキーワードを変数名として使用しない理由です。変数を「入力」以外の名前で呼び出すと、コードが正常に動作するはずです。

于 2013-02-28T20:23:51.580 に答える