+ 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?
14 odpowiedzi
+ 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)
+ 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.
+ 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
+ 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. ;-)
+ 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
+ 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
+ 4
Where is your input which you are taking share here.
+ 3
This looks like it has to do with Sololearn input modalities.
https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
+ 2
The input is
3
2
1
0
Por example
+ 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)
+ 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
0
David Martínez can you share your exact input?. so what do you actually type in the input?
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.
- 1
Try to use while instead of the for loop