Python, Error while taking input

I have been working with Python 3 for quite a while, however, I am new to CodeChef. I have tried to solve quite a few practice problems using CodeChef IDE. However, every time I try to run it, I get the following error.

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

I try running the same code with custom input and it works perfectly. The first line of my code, where the error occurs is the following:

t = int(input())

  1. I have checked the version, and it is Python 3 only. Hence, there is no problem with input()
  2. The first line of input is a single integer, hence, converting the string into int should not be an issue. For more details, i am sharing the link to the problem as well which I am trying to solve.
    Link: here

I also tried the following:

import sys
inp=sys.stdin.read()
print(inp)

In this case, the output was nothing. Can someone help me out with what the problem is actually?

5 Likes

I am having the same problem, except I got the error both in competition and with the ide. I would also appreciate a solution. The error is occurring with this line:

t = int(input())

1 Like

If your code takes some input, then you have to provide custom input for your program otherwise it will show NZEC error. Just provide an appropriate input and it works fine.

1 Like

For the contest and practice submissions, isn’t codechef supposed to provide the input? I’m getting that error with contest and practice submissions. I notice my code works on some online compilers and not others, with codechef being one of the compilers it doesn’t work on.

1 Like

I am also facing the same issue. Did anyone find a solution?

Hey, you guys should try just submitting. It works. I think ‘RUN’ and ‘SUBMIT’ run on different compilers/machines and ‘RUN’ is broken right now.

If you are trying to run the code in IDE mode then you must provide custom input, otherwise you will get NZEC.
This is the only reason you are getting this error. If you wanna submit then just submit. So RUN and SUBMIT both are different functionalities. In case of SUBMIT, codechef gives it’s test cases. But in case of RUN, you should give input.

5 Likes

Text Input
Want to get keyboard input?

To get keyboard input, use the input function. Inside the terminal you’ll be able to type text.

In Python 3 you can use the input() function, older versions of Python have the raw_input() function.

Related Courses: Python Crash Course
User Input
The input function has a return variable. In this case the keyboard input. If we do not store the return variable into a programs variable, we lose it. That’s why we write a variable to store the result in.

To get a text value:

name = input("Enter a name: ")
print(name)

This will show you:
Enter a name:

You can now give keyboard input, it will be stored in the variable name.

Note: don’t forget to store the return variable. variable = input(“…”)

I was also facing the same issue 2 days back…when I was in a competition organized by Jaypee College…It really sucks…I think some times using strip() with input helps…:slight_smile:

You are getting EOF error. That means there was no input but you still tried to read something. Can you share your submission link for which you are getting this error?

Hi,
The link to my solution is the following:
https://www.codechef.com/viewsolution/22062856

This code worked perfectly during the competition, but it is not running in the ide. I have been getting the same error for all the problems that I have attempted so far in ide.
Thanks for your help.

After banging my head for for some time I got the solution.
The IDE expects custom input to be provided.
Just select Custom input below IDE box and copy paste the input values provided with problem statement in the Custom input box below Run/Submit.
Bingo, whatever you did will be run successfully.
This should make things work for any language since IDE expects custom input.
But codechef should not be that dumb to tax people & provide inputs all the time. They should improve.

i have used codeforces and hackerearth where these in(input()) works really fine,codechef is a little different it works when i m not in ide mode otherwise it does not.codechef sholud improve its inbuilt ide.

you to give the input in the custom input so that it can take an input from there

Can you give an example, please? I don’t understand what you mean with ‘Just provide an appropiate…’. Thank you!

When I run the code with costume input it works perfectly fine and also provide the correct output. While submitting provide me the NZEC error! Please help me.

I am also getting the same error. while taking input:
here is my sample code:

number_of_input = int(input())
for j in range(number_of_input):
action, val = input().split()
val = int(val)
if action == ‘i’:
bst.insert(val)
elif action == ‘d’:
bst.delete(val)
else:
print(“input error”)
pass

i am getting EOFerror in first line. when i am trying to submit code. it’s running perfectly with sample input or in my Intelliz ide.

Please help or provide solution.
Thanks in advance.

use
action,val=map(int,input().split())

For this problem: t = int(input()) and showing the error of EOF. Just switch to non-ide mode and then submit the code, it will run and submit successfully.

could you please explain how does it happen