2013-02-28 79 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(",", ""))