Manas Chaturvedi
Manas Chaturvedi

Reputation: 5540

Python- EOFError: EOF when reading a line

I'm trying to solve a problem using the following code:

def inmobi(t):
    while t:
        li = map(int, raw_input().split())
        n, ans = li[0], li[1:]
        one, two, op = [], [], []
        for e in range(n):
            for i in range(1, n):
                if e + i < n:
                    one.append(ans[e] + ans[e + i])
        two = sorted(one)           
        print two[n-1] - two[n-2]
        t += 1
t = int(raw_input())
inmobi(t)

This code gives me the desired output when I run using the Linux shell in Ubuntu. However, when I try running this code using an interpreter provided by a competitive programming website, I get the following error:

Traceback (most recent call last):
  File "/tmp/editor_trsource_1438181626_447674.py", line 14, in 
    inmobi(t)               
  File "/tmp/editor_trsource_1438181626_447674.py", line 3, in inmobi
    li = map(int, raw_input().split())
EOFError: EOF when reading a line

I tried reading the answers of other similar questions, but none of them seemed to work in my case.

Upvotes: 0

Views: 3048

Answers (1)

Anand S Kumar
Anand S Kumar

Reputation: 90889

I am assumming according to the competitive programming website, the first line of input is the number of testcases (which is normally the case).

Your issue is basically in line -

t += 1

Here , you keep increasing the value of t , but your while condition is while t: , t never goes down and hence while loop never exits, so basically the while loop is an infinite loop and soon after the inputs form the programming competition site get exhausted causing the EOFError you are seeing. I have no idea how it worked for you in linux, but it should have went into infinite loop there as well. You should decrease t , not increase it.

t -= 1

Upvotes: 1

Related Questions