Created
June 24, 2014 14:23
-
-
Save sumoward/43717356cdad2adaacbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def checkio(array): | |
""" | |
sums even-indexes elements and multiply at the last | |
""" | |
length = len(array) | |
if length == 0: | |
return 0 | |
ans = 0 | |
for x in range(length): | |
if x==0 or x%2 ==0: | |
ans = ans + array[x] | |
return ans * array[length -1] | |
#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, "Empty" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
checkio = lambda array: sum(array[::2]) * sum(array[-1:])