my solution to "That's odd" doesn't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

my solution to "That's odd" doesn't work

n=int(input()) sum=0 for i in range(n): num=int(input()) if (num%2)==0: sum=sum+num print(sum) The error: Traceback (most recent call last): File "./Playground/file0.py", line 5, in <module> num=int(input()) EOFError: EOF when reading a line in my PC it works, but in Sololearn it doesn't. What is the problem?

19th Dec 2019, 11:19 AM
David Martínez
David Martínez - avatar
14 Answers
+ 3
okay. with that example the first number is 3 and this will be the input for the variable n because n == 3 the range of your for loop will be 3 as long as the first number you input in your “list” of inputs is the same as the amount of numbers that follow after the programme should work. so 5 2 1 0 shouldn’t work :) 5 4 3 2 1 0 should work. this is because of how sololearn input works (it needs all the input before running the programme and can’t ask for new input whilst running the programme)
19th Dec 2019, 1:50 PM
Brave Tea
Brave Tea - avatar
+ 11
n=int(input()) sum=0 for i in range(n): num=int(input()) if (num%2)==0: sum=sum+num print(sum) Now it works. I dont understand why.
19th Dec 2019, 12:35 PM
David Martínez
David Martínez - avatar
+ 7
The reason why it fails in SL is the special input behavior of SL PlayGround. You have 2 input() functions in your code, but where you have to keep in mimd that the second one is running repeatedly in a loop. You can find here some more information to this issue: https://code.sololearn.com/c8pQgA9MTOj5/?ref=app
19th Dec 2019, 11:31 AM
Lothar
Lothar - avatar
+ 6
You've rediscovered one if the oftentimes shared truths of programming: You spend a lot of time not knowing why it either fails or succeeds. ;-)
19th Dec 2019, 1:21 PM
HonFu
HonFu - avatar
+ 6
n=int(input()) sum=0 for i in range(n): num=int(input()) if (num%2)==0: sum=sum+num print(sum) This code is working
3rd Nov 2020, 5:46 PM
Ahadjon Naimov
Ahadjon Naimov - avatar
+ 4
Yes here it will not work because you are taking input one by one. If you have multiple inputs then you can take like this:- 223 345 700
19th Dec 2019, 11:28 AM
A͢J
A͢J - avatar
+ 4
Where is your input which you are taking share here.
19th Dec 2019, 12:06 PM
A͢J
A͢J - avatar
+ 3
This looks like it has to do with Sololearn input modalities. https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
19th Dec 2019, 11:27 AM
HonFu
HonFu - avatar
+ 2
The input is 3 2 1 0 Por example
19th Dec 2019, 1:31 PM
David Martínez
David Martínez - avatar
+ 2
Try it for #Python n=int(input()) sum=0 for i in range(n): num=int(input()) if (num%2)==0: sum=sum+num print(sum)
2nd Feb 2022, 10:14 AM
Avrian Shandy
Avrian Shandy - avatar
+ 1
So... what can i do? the input is a list, but i cant use n[i] for iterate: IndexError: list index out of range
19th Dec 2019, 11:36 AM
David Martínez
David Martínez - avatar
0
David Martínez can you share your exact input?. so what do you actually type in the input?
19th Dec 2019, 1:25 PM
Brave Tea
Brave Tea - avatar
0
Mine works in VS code with 'sum =+ elem' - BUT here, it only works with a 'sum = sum + elem'. Bear in mind Sololearn's playground works differently than IDLE. I've just spent an hour trying to figure out the bug that wasn't there.
15th Aug 2022, 11:03 AM
Monika
- 1
Try to use while instead of the for loop
5th May 2022, 4:10 PM
Mohamed Wagdy
Mohamed Wagdy - avatar