suyashsingh234
suyashsingh234

Reputation: 189

Python- Runtime error(NZEC)

Question-

https://www.codechef.com/problems/SINS

Compiler used-

https://www.codechef.com/ide

Input method-

Custom input of codechef compiler.

My attempt-

T=int(input())
def fnc(a,b):
    if b!=0:
        return fnc(b,a%b)
    else:
        return int(a*2)
while T>0:
    X,Y=map(int,input().split())
    if X==0:
        print(Y)
    elif Y==0:
        print(X)
    elif X==Y:
        print(X*2)
    else:
        f=fnc(X,Y)
        print(f)
    T=T-1

Issue:

I am getting the following runtime error:

Traceback (most recent call last):
   File "./prog.py", line 8, in <module>
 EOFError: EOF when reading a line

The output is correct but still there is this runtime error.

Upvotes: 0

Views: 298

Answers (1)

cdarke
cdarke

Reputation: 44354

That is because the input() is getting End Of File (I assume you are using Python 3). You need to trap the EOFError exception and break out of the loop when you get it. You asked what I meant by that comment, this is what I mean:

try:
    X, Y = map(int, input().split())
except EOFError:
    break

Upvotes: 0

Related Questions