728x90
You are given an array of integers. You should find the sum of the integers 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 0 (zero).
Input: A list of integers.
Output: The number as an integer.
Example:
checkio([0, 1, 2, 3, 4, 5]) == 30
checkio([1, 3, 5]) == 30
checkio([6]) == 36
checkio([]) == 0
* 0, 2, 4 번째 숫자들을 더하고 마지막 숫자를 곱한다.
* array가 비었으면 0 을 출력한다.
- 풀이
def checkio(array):
result = 0
if not array:
return 0
else:
for i in range(len(array)):
if i % 2 == 0 :
result = result + array[i]
result = result * array[-1]
return result
반응형
'취미생활 > CheckIO' 카테고리의 다른 글
[checkIO]Element 09.Correct Sentence (0) | 2020.03.18 |
---|---|
[checkIO]Element 08.Best Stock (0) | 2020.03.14 |
[checkIO]Element 06.Fizz Buzz (0) | 2020.03.03 |
[checkIO]Element 05.Secret Message (0) | 2020.03.01 |
[checkIO]Element 04.Digits Multiplication (0) | 2020.02.26 |