0
Why am I getting EOF error?
What is happening this code is not working for some reason. Its keeps giving me EOF error on line 4. Please explain to me what this means and how to fix it x = 100 while x < 9999999: if str(input()) == "hit": print(x + 10) if str(input()) == "miss": print(x - 20) x += 4
2 Answers
+ 4
you got EOF (End Of File) error in sololearn, because sololearn playground run script as server side... so it ask for all input at once, each separated by a new line (no real interactivity).
as you loop run infinitly, you cannot provide enough input as expected (x much be greater or equal to 9999999, and is never increased)...
x += 4 is never reached as outside of the body loop
first 'if' inside loop body expect an input, and second 'if' expect another input... so two inputs by iteration, and you only print x+10 and/or x-20 (or even nothing at all) but don't update x value ;P
logical way to test if input equals "hit" or "miss" would be to do input only once (inside the loop), store the value in a variable, and then use that variable for both 'if' update x value and finally output the updated (or not) x value:
while x<9999999:
inp = input() # input is already a string, no need of str() function
if inp == "hit": x += 10
if inp == "miss": x -= 20
print(x)
+ 3
however, to get a fixed number of input, you must have another variable to count loop iterations by incrementing it at each turn, and test if it is less than the number of input expected:
i = 4 # number of input expected
n = 0
while n < i:
# do the stuff
n += 1
or simpler:
n = 4 # number of input
while n:
# do the stuff
n -= 1
or even simpler and shorter:
for n in range(4):
# do the stuff