提问人:TY.OVICNE 提问时间:3/1/2017 最后编辑:Keerthana PrabhakaranTY.OVICNE 更新时间:3/1/2017 访问量:44
我收到 EOF 错误,我正在努力修复它
I am getting an EOF Error and i am struggling with fixing it
问:
当我在
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
答:
0赞
Keerthana Prabhakaran
3/1/2017
#1
在 python 2.7 中,input() 将用户输入作为表达式运行。
所以,在改成应该做!input()
raw_input()
operation = raw_input("what do you want to do (+,-,/,*):")
这应该会有所帮助!
评论
0赞
Keerthana Prabhakaran
3/1/2017
如果它回答了您的问题,请接受答案!
评论