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
Created at: 2019/12/30 12:56; Updated at: 2020/01/13 14:03