+ 1
What is EOFERROR in Python?
n = int(input()) sum = 0 while 0<=n: x=int(input()) if x%2==0: sum = sum + x n=n-1 print(sum) This is my code and I see the error ... I cant figure it out , plz help me .
4 Respostas
+ 5
The decrement of n has to be in the while loop and not in the if statement. So you can better count how many input data should be take.
EOF coming when the input statement gets no data.
n = int(input())
sum = 0
while n>0:
x=int(input())
if x%2==0:
sum = sum + x
n=n-1
print(sum)
+ 1
JaScript thank you so much.
+ 1
EOF means end of file, this is a confusing error because you wouldn't normally have that outside of sololearn. The problem might be caused by not giving enough inputs to your program: if you first number is 4, than you need to add 4 other number to match your loop. if the first is 2 than you need to add 2 other numbers.
So why is it saying EOFERROR? because Sololearn save your inputs to a file and give it to your code when you start it. If your code has more inputs than what you give (getting to the end of the file) it will crash.
I hope this helps :)
+ 1
Apollo-Roboto thank you 😄 that's logically true 👍👍👍