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

11th Sep 2021, 3:43 PM
Emma Cooke
11 Respuestas
+ 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.
11th Sep 2021, 3:52 PM
Sai Sudarshan B V
+ 1
Thanks
11th Sep 2021, 4:01 PM
Emma Cooke
0
Another common cause of EOF errors are missing closing parentheses.
11th Sep 2021, 3:58 PM
Simon Sauter
Simon Sauter - avatar
0
I almost forgot. Missing closing quotation marks are also a common cause of end of file errors.
11th Sep 2021, 6:18 PM
Simon Sauter
Simon Sauter - avatar
0
Thanks
11th Sep 2021, 7:02 PM
Emma Cooke
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)
12th Sep 2021, 10:33 AM
Emma Cooke
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.
12th Sep 2021, 10:52 AM
Emma Cooke
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)
12th Sep 2021, 11:12 AM
Simon Sauter
Simon Sauter - avatar
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.
12th Sep 2021, 11:16 AM
Simon Sauter
Simon Sauter - avatar
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)
12th Sep 2021, 11:31 AM
Emma Cooke
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
12th Sep 2021, 1:31 PM
Simon Sauter
Simon Sauter - avatar