0
What's an EOF error? My code is coming up with it on one of my lines atm and I don't know what it is thus how to get rid of it.
EOF error
11 ответов
+ 5
EOF - Error is raised when one of the built-in functions input() or raw_input() hits an end-of-file condition (EOF) without reading any data. This error is sometimes experienced while using online IDEs. This occurs when we have asked the user for input but have not provided any input in the input box. We can overcome this issue by using try and except keywords in Python.
+ 1
Thanks
0
Another common cause of EOF errors are missing closing parentheses.
0
I almost forgot. Missing closing quotation marks are also a common cause of end of file errors.
0
Thanks
0
Can you tell me what's wrong with this code (line 4)? This is the code that's producing the EOF error. Thanks
i = 0
points = 100
while i <= 4:
action = input()
if action == ("hit"):
points += 10
elif action == ("miss"):
points -= 20
i += 0
print(points)
0
i = 0
points = 100
while i <= 4:
action = input()
if action == ("hit"):
points += 10
elif action == ("miss"):
points -= 20
i += 0
print(points)
I presume that's what you meant. I've tried that but it's still producing the error. It's referring to line 4 (the input line) but I can't see anything wrong with it.
0
This time you've indented it too far. It has to execute in every iteration of the loop. Also it has to be i+=1.
i = 0
points = 100
while i <= 4:
action = input()
if action == ("hit"):
points += 10
elif action == ("miss"):
points -= 20
i += 1
print(points)
0
The reason for the eof error in your case is that your counter i isn't increased in every iteration of the loop. That means that your while condition is true for more iterations than intended. That in turn means that there are more iterations. And since each iteration requires input but sololearn only gives a specific number of inputs your code runs out of inputs.
0
So I've tried what you suggested (below) and the error is still there. I'm so confused.
i = 0
points = 100
while i <= 4:
action = input()
if action == ("hit"):
points += 10
elif action == ("miss"):
points -= 20
i += 1
print(points)
0
What Calvin T suggested should work. If I remember correctly sololearn gives you four inputs. So the loop should have four iterations.
That means you can either start with
i = 0
and use
while i < 4:
or you can start with
i = 1
and use
while i <= 4