2

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

X,Y = map(float, input().split())

if X < Y and not X % 5:
    print(Y - X - 0.50)
else:
    print(Y)

This code gives me the desired output when I run using IDLE. 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 "./prog.py", line 1, in <module>
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.

Bill Bell
  • 21,021
  • 5
  • 43
  • 58
deezpeeps
  • 114
  • 2
  • 10
  • Maybe the interpreter isn't passing any information to stdin, so your `input` call fails to get anything. Are you sure you're supposed to be getting X and Y through input? Maybe they're actually command line arguments or something. What competitive programming website is this, specifically? – Kevin May 05 '17 at 17:29
  • Without having actual samples of the problem, it's hard to say. Try debugging this by decoupling your input process: grab a line of input, check its contents for validity, print the line, etc. See what sort of input is crashing your program. It may be as simple as recognizing a null line at the end of the file. – Prune May 05 '17 at 17:30
  • What is the function call `input()` ? is that supposed to be the standard python 3.x [`input()`](https://docs.python.org/3/library/functions.html?highlight=input#input)? maybe need to pull that line out out, and first `user_input = input().split()` and get the result first, then pass that user input into `map(float, user_input)` – chickity china chinese chicken May 05 '17 at 17:30
  • @Kevin It's CodeChef – deezpeeps May 05 '17 at 18:47
  • @Prune The values do get recognised and work in IDLE – deezpeeps May 05 '17 at 18:50
  • @downshift Yes, It's the standard input() in 3.x. I tried your suggestion i.e. input().split() too, doesn't work. – deezpeeps May 05 '17 at 18:50
  • @user3632345: I understand that it works in IDLE. I'm wondering what output you get when you run on CodeChef. Do you not get to see the full output? – Prune May 05 '17 at 18:54
  • @Prune I get the error. No output. That's the problem. (Also, trying the problem in c++ works out fine) – deezpeeps May 05 '17 at 19:09

3 Answers3

2

I am not sure of the reason but the program is trying to read after the end of the data. You can solve the problem by exception handling

try:
    data = input()
except EOFError:
    break
1

The competitive programming website is likely running python 2. Python 2 treats input() differently than python 3.

You should rather use raw_input() than input().

From the docs:

raw_input() reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

Your problem can be explained from what was explained here:

In Python 2, raw_input() returns a string, and input() tries to run the input as a Python expression.

Community
  • 1
  • 1
Hafager
  • 30
  • 3
  • 2
    You can choose which language to run it in. So, no that's not the problem. I'm explicitly running it in python 3.4 – deezpeeps May 05 '17 at 18:51
  • Are you providing the input using the "custom input" feature on codechef? I did not run into any problem providing: `1 2` – Hafager May 05 '17 at 18:58
  • custom works fine. Just not their input. For reference use problem code HS08TEST in the compiler – deezpeeps May 05 '17 at 19:08
  • I think you need to clarify exactly where you are running the code and what input you are providing. – Hafager May 05 '17 at 20:15
1

Take another look at the codechef page. Notice the checkbox marked 'Custom Input'. With that checked/ticked a textbox will open where you can put your input lines.

codechef image

Bill Bell
  • 21,021
  • 5
  • 43
  • 58