This is the problem description at checkIo -
"You are given an array of integers. You should find the sum of the elements with even indexes (0th, 2nd, 4th...) then multiply this summed number and the final element of the array together. Don't forget that the first element has an index of 0. For an empty array, the result will always be (zero)."
The result is supposed to be this -
if __name__ == '__main__':
assert checkio([0, 1, 2, 3, 4, 5]) == 30, "(0+2+4)*5=30"
assert checkio([1, 3, 5]) == 30, "(1+5)*5=30"
assert checkio([6]) == 36, "(6)*6=36"
assert checkio([]) == 0, "Empty"
This is what I came up with -
def checkio(array):
total = sum(array[::2]) * array[-1]
return total
It works okay with the first 3 results. The last one gives assertion error saying Index out of range. I am not able to get around this issue. There is a possibility that whole of my code is wrong. But since first three are success, I am not able to say whether it is.
Lastly, I don't understand what this is for -
if __name__ == '__main__':