When one doesn't type anything into the input box, you would think the array-list would be empty. Instead, the program has no output at all. It should have the output "0" Nevertheless the system declared that this program has solved the task...
=================
def checkio(array):
"""
sums even-indexes elements and multiply at the last
"""
print ("the list is ", len(array), " items long.")
if array == []:
array = [0]
last = array[len(array)-1]
indices = [i for i in range(len(array)) if (i % 2 == 0)]
addenda = [array[a] for a in indices]
sadd = sum(addenda)
return sadd*last
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"
Created at: 2014/12/14 23:45; Updated at: 2014/12/14 23:45