Taking input Python

did you get any solution? i have similar problem

7 Likes

Same here. The code is working fine with custom input. But submission fails. @imsankeerth: How did you take input in CHFM problem?

6 Likes

If u write a recursive solution with depth greater than 1000, then it can also cause nzec.

1 Like

I just started codechef and I’m too getting that EOF error each time when the code is allowed to get compiled with system’s input.
For some programs i could find solution when custom input is provided.
and also you can better try :
try … except …

2 Likes

Even i’m having the same problem!

First of all, don’t use codechef IDE. It’s very slow and most of the time it sucks. Even though you are using it, provide custom input test cases.

You can also use ‘try and except’ in your code.
try:
----your code----
----your code----
----your code----
except EOFError as e : pass

An EOFError is raised when a built-in function like input() or raw_input() do not read any data before encountering the end of their input stream.

For python refer to: Python input/output for competitive programming.

For matrix input in python: matrix = [[ int ( input ()) for x in range (C)] for y in range (R)] , where R is no. of Rows and C is no. of Columns.

4 Likes

You can use readline() from sys package. Refer the following lines of code:
import sys
t = int ( sys.stdin.readline() )
print(t)

2 Likes

https://www.codechef.com/viewsolution/25360383

^^ That’s my take on the BST operations challenge. When I run the code (without custom input), i get an empty input stream which returns “invalid literal for base 10”. But with custom input it runs perfectly. The same thing happens when I submit it. Is there something wrong with my code?

1 Like

thanks dude it worked

1 Like

try this
x = input().split(’ ‘)
then x will be a list with every element as string
so you need to convert each element into int by type casting
example:
code:-
x = input().split(’ ')
print(x)

input:-
1 2 3
o/p:-
[‘1’, ‘2’, ‘3’]

3 Likes

Thanks it really works

its working…bt it increased my code execution time by 5sec nd now it shows TLE(Time Limit exceeded) error.
Wanted to know what to do.
Is there any other way to handle this exception?

3 Likes

take custom input and run…

thank you so much !!

T=int(input())
for _ in range(T):
    N=int(input())
    d={}
    maxscore=0
    for i in range(N):
        p,s=map(int,input().split())
        if p in d.keys():
            d[p]=max(d[p],s)
        else:
            d[p]=s
        for j,k in d.items():
            if j<1 or j>8:
                pass
            else:
                maxscore+=k
    print(maxscore)

Traceback (most recent call last):
File “./prog.py”, line 23, in
EOFError: EOF when reading a line

help me to solve this error

Are you trying to Run without providing Custom Input?

for this, you can set the recursion limit bu following line :
sys.setrecursionlimit(10**6)

You need to provide an input type…
Like:
x = int(input())

thanks for the solution it worked like a charm
will it work for all the programs?

Yeah it worked