Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python EOF error when reading input

Tags:

python

n = input()
dum = input()
d = {}
for i in range(0,n+1):
    x = raw_input()
    x = x.split(" ")
    d[int(x[0])] = int(x[1])

array = d.keys()

for key in d.keys():
    if(d[key]!=0):
        if(d[key] not in d.keys()):
            for i in d.keys():
                for j in d.keys():
                    if(i!=j and i!=key and j!=key):
                        if(i+j==d[key]):
                            # print str(i)+"-"+str(j)
                            if(i in array):

                                array.remove(i)
                            if(j in array):
                                # print j
                                array.remove(j)
        else:
            # print d[key]
            array.remove(d[key])
print array[0]

When I execute this Python code I am getting "EOF error when reading input".

Can you please help? I am running Python 2.7.5

Error Traceback

Traceback (most recent call last):
File "prog.py", line 1, in <module>
EOFError: EOF when reading a line
like image 996
Mark Avatar asked Feb 27 '16 10:02

Mark


1 Answers

I can't seem to reproduce this error although using the same input as you did. Maybe you have a newline character before the input you have specified?
Try running this code using python prog.py in your terminal.

EOF error is expected if no data is given when calling input or raw_input as explained in the documentation.

Also, it's advisable to use raw_input and not input when getting input from the user on python 2, it's not going to fix your error though.

like image 95
Forge Avatar answered Oct 01 '22 07:10

Forge