Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 解析时出现意外的EOF???_Python - Fatal编程技术网

Python 解析时出现意外的EOF???

Python 解析时出现意外的EOF???,python,Python,所以我试图创建一个简单的计算器,我认为这段代码没有任何错误,但当我运行代码时,它说有语法错误:在解析([字符串],第1行)时出现意外的EOF,我尝试了一些更改,但我仍然看不到错误,请帮助我 operation = input ("Pick your operation: + | - | * | / ") if operation == '+' : no1 = int(input ("Pick a number")) no2 = int(

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

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.")

您的行在Python2和Python3中都有效,但仅在Python3中才有意义

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

在Python 2中,您必须使用
raw\u输入

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

有关详细信息,请阅读和上的文档。

对于python版本<3.0,您需要使用
raw\u input
。您可能需要检查Python的哪个版本,2或3?可能的副本