What is EOFERROR in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 .

7th May 2021, 7:57 PM
Ali_combination
Ali_combination - avatar
4 Answers
+ 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)
7th May 2021, 8:06 PM
JaScript
JaScript - avatar
+ 1
JaScript thank you so much.
7th May 2021, 8:13 PM
Ali_combination
Ali_combination - avatar
+ 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 :)
7th May 2021, 8:14 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Apollo-Roboto thank you 😄 that's logically true 👍👍👍
7th May 2021, 8:16 PM
Ali_combination
Ali_combination - avatar