Reputation: 114
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.
Upvotes: 2
Views: 9852
Reputation: 31
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
Upvotes: 2
Reputation: 30
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.
Upvotes: 1
Reputation: 21643
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.
Upvotes: 1