0
EOF Error, Python.
Hi! I've just started learning python and I keep getting the eof (end of file) error when I try to solve a problem. So, there must be an endless input process and I have to make the program stop when I type "0". But there is something wrong with that and it says that «n = int(input())» string is the cause of it. It would be cool if anyone here could help with that. Here is the code I wrote: items = [] while True: n = int(input()) items.append(n) if (n == 0): break print(items)
4 Respuestas
+ 3
The SoloLearn playground requires that ALL inputs for the runtime duration of the program be entered at once in the input prompt. In the case of your program, if you do not have the last input as 0 then you will receive the EOF error. It's not an issue with your program, but a limitation of the playground. If you ran your code elsewhere, such as your PC, it would run as expected.
0
Hi! You have to catch the error with:
try:
”your code that cause the error”
except EOFError:
”code of what is happened when error occure”
0
# Try this code:
lst = []
try:
while True:
n = int(input())
lst.append(n)
if (n == 0):
break
except EOFError:
print("Ops! Last input must be zero! (EOFError)\n")
print("=>", *lst)
0
Thanks to everyone for the advice! I'll try to change the code a bit and run it on pc later.