简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM