解析时意外的EOF ???

时间:2015-09-12 14:17:22

标签: python

所以我试图创建一个简单的计算器,我认为这个代码没有任何问题但是当我运行代码时,它说有语法错误:解析时意外的EOF([字符串],第1行)我尝试了几个更改,但我仍然无法看到错误,请帮帮我?

operation = input ("Pick your operation:  +  |  -  |  *  |  /   ")

    if operation == '+' :
        no1 = int(input ("Pick a number"))
        no2 = int(input ("Pick another number"))
        answer = no1 + no2
        print ( "Answer:", no1 , "+" , no2 , "=", answer)

    elif operation == '-':
        no1 = int(input ("Pick a number"))
        no2 = int(input ("Pick another number"))
        answer = no1 - no2
        print ( "Answer:", no1 , "-" , no2 , "=" , answer)

    elif operation == '*':
        no1 = int(input ("Pick a number"))
        no2 = int(input ("Pick another number"))
        answer = no1 * no2
        print ( "Answer:", no1 , "*" , no2 , "=", answer)

    elif operation == '/':
        no1 = int(input ("Pick a number"))
        no2 = int(input ("Pick another number"))
        answer = no1 / no2
        print ( "Answer:", no1 , "/" , no2 , "=", answer)

    else:
        print ("Please check your given options of operations.")

2 个答案:

答案 0 :(得分:2)

你的行在Python 2和3中都是有效的,但它只在Python 3中有用。

版本之间的输入行为发生了变化。

在Python 2中,您必须改为使用raw_input

operation = raw_input("Pick your operation:  +  |  -  |  *  |  /   ")

阅读https://docs.python.org/2.7/library/functions.html#inputhttps://docs.python.org/3/library/functions.html#input上的文档了解详情。

答案 1 :(得分:0)

你需要使用raw_input用于python版本< 3.0。您可以查看behavior of input