Light Mode
Dark Mode
Even the last - why is code not passing test 11

This is my code below.

def checkio(array):

if len(array)==0:

return 0

else:

sum=0

for x in array:

if array.index(x)%2==0:

sum+=x

print(sum)

return (sum*array[-1])

Test 11 is

checkio([-37, -36, -19, -99, 29, 20, 3, -7, -64, 84, 36, 62, 26, -76, 55, -24, 84, 49, -65, 41])

I used print(sum) to give me some clue what is going on. I got the output below.

-37

-56

-27

-24

-88

-52

-26

29

-36

It seems that everything went well until it reached the 16th element in the array. (it seemed to have skipped it) Really confused why this happened. Would be really grateful if someone could try to explain it. thanks

  • bug
  • code_review
  • python
Created: Dec. 30, 2019, 12:56 p.m.
Updated: Jan. 13, 2020, 2:03 p.m.
0
4
User avatar
uyoahsgno