0
What is wrong with this code looking for even numbers?
That's the code coach challenge THAT'S ODD... The task is to find the sum of all even numbers in the list. What is wrong with my code? https://code.sololearn.com/cD82UGD56367/?ref=app
3 Answers
+ 6
blackfish ,
the input procedure you presented in your code is a bit different from the one that is mentioned in code coach < that's odd > :
- The first input denotes the length of the list (N). The next N lines contain the list elements as integers.
âȘïžin this case the first number in taken and converted to int. then a loop can be started and take the N elements. in playground each of these number has to be written in a new line. they also have to be converted to int and then stored in a list.
âȘïžcreate a variable < total > that can hold the running sum of all even numbers
âȘïžthen iterate trough the list with a for loop, check each element of the loop variable if it is even. if yes, add this number to the total var
after the iteration is finished, total holds the sum of all even numbers
0
Jay Matthews Thank you. But what's the input in you propsal? Is it just one number? In the first test the input is: 5, 190, 88, output should be: 278. Which I got, but cannot pass the test. In the second: 1, 191, output: 0.
I'm confused...
0
I understood that the input is list of numbers, not an integer, which is use to create a list of numbers...
Using your suggestion in the code from the first test I got 6, which is wrong đ