I'm really not under standing why I get this error. "IndexError: list index out of range
checkio, 5
<module>, 18"
def checkio(array):
answer = 0
if len(array) != 0:
for i in array[::2]:
answer += array[i]
answer *= array[-1]
return answer
else:
return answer
/#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print('Example:')
print(checkio([0, 1, 2, 3, 4, 5]))
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, "An empty array = 0"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Also could someone help point to where I can find out how to insert the code correctly into posts?
https://gist.github.com/MyceliumMark/04ae69cce1c535d0c69a3ece99361657
Created at: 2019/07/15 04:12; Updated at: 2019/07/16 02:23
The question is resolved.