我得到一个EOF错误,我正在努力修复它

时间:2017-02-28 21:51:42

标签: string eof

我在

输入输入时出现EOF错误
operation = input("what do you want to do (+,-,/,*):")

这是代码

def add(num1, num2): #function signature
    return num1 + num2

def sub(num1, num2): #function signature
    return num1 - num2

def div(num1, num2): #function signature
    return num1 / num2

def mul(num1, num2): #function signature
    return num1 * num2


def main():
    operation = input("what do you want to do (+,-,/,*):")
    if(operation != '+' and operation != '-' and operation != '/' and operation != '*'):
       print("you must enter a valid operation")
    else:
        var1 = int(input("Enter num1: "))
        var2 = int(input("Enter num2: "))
        if(operation == '+'):
            print(add(var1, var2))
        elif (operation == '-'):
            print (sub(var1, var2))
        elif (operation == '/'):
            print (div(var1, var2))
        else:
            print (mul(var1, var2))
main()

这是错误!

File "<string>", line 1
    +
    ^
SyntaxError: unexpected EOF while parsing

1 个答案:

答案 0 :(得分:0)

在python 2.7中,input()将用户输入作为表达式运行。
因此,在更改为--prefix=/fooinput()时应该这样做!

raw_input()

This应该有帮助!