6
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
5
  • I am getting IndexError: list index out of range Commented Feb 27, 2016 at 10:24
  • Please include the full error traceback. Commented Feb 27, 2016 at 10:25
  • If array is empty, you would get that. But I am unable to execute the code because of EOF error. Commented Feb 27, 2016 at 10:25
  • @Forge I have included the error traceback Commented Feb 27, 2016 at 10:27
  • 5 6 11 21 21 0 31 52 41 61 61 0 Commented Feb 27, 2016 at 10:30

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

In Python 2, raw_input() returns a string, and input() tries to run the input as a Python expression. So, changing your first line to something like this should work.

n = int(raw_input())

According to the official documentation

Equivalent to eval(raw_input(prompt)).

This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.

Comments

0

This:

for i in range(0,n+1):

does n+1 number of iterations, yet your input file:

5
6
11 21
21 0
31 52
41 61
61 0

Only has n number of lines remaining when that loop is about to start. Upon attempting to read a n+1th line, you'll get an EOFError as there are no more lines.

Comments

0

I was really confused by this problem as well, and I couldn't find the direct answer on other resources.

However, what the issue was for me was I am using PyCharm and my configurations for my .py file were wrong. Basically, I had it looking for an external file to source input from instead of the console.

I had to change these configurations by unchecking the "emulate terminal in output console" box in the picture below and then it worked perfectly.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.