Light Mode
Dark Mode
Out of index exception

I would like to give some feedback about ...

From: http://www.checkio.org/mission/even-last/solve/

HTTP_USER_AGENT:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36

The following code gives out of index exception when it works on my local shell

def checkio(array): sum = 0 l = [index for index in range(len(array)) if index % 2 == 0] for index in l: sum = sum + array[index]
return array[-1] * sum

These "asserts" using only for self-checking and not necessary for auto-testing

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, "An empty array = 0"

  • feedback
Created: Feb. 12, 2015, 12:45 a.m.
Updated: Feb. 12, 2015, 3:16 a.m.
0
4
User avatar
SureshShenoy