+ 1
What does an EOFError is?
10 Antworten
+ 3
Please post your complete code in playground and link it here. We need to see the code to find out why the error is happening.
+ 2
EOFError means End Of File error. It is thrown when nothing is inputted.
+ 1
Yup, i usually get it when im missing an end parenthesis or something similar
+ 1
An EOFError is raised when a built-in function like input() or raw_input() do not read any data before encountering the end of their input stream. The file methods like read() return an empty string at the end of the file. The given code is rewritten as follows to catch the EOFError and find its type.
+ 1
There are several reasons that causes errors in the current code:
- When an odd number is entered, you run in an infinite loop with the while ... loop. Even if you enter an even number in the second try, iyou are caught in this loop. So this needs a correction with a break.
- If the same case happens in sololearn playground, you get an EOF error, because there is no input done for this case (repeated input)
- The input in the while loop should also convert the entered number to int, as it's done with the first input .
To get rid of these things, you should modify your code like this:
while int(comprobation)!=0:
print("It must be an even number")
number=int(input("Enter a number: "))
if number % 2 == 0:
break
0
It works fine man
0
Kevinator
It works fine in case of even number input. But cause error when we enter odd number.
The reason is that in case of odd number while loop executes and it prompt user for input but due to limitations of sololearn playground we can'nt give any input at runtime so that's why error occured.
If you try same code on any other ide it works fine.
0
If you input an odd number it shows the error
0
Thanks for everything