← Back to challenges

Even Index Elements in a List

PythonMediumarrayslanguage_fundamentalsnumbers

Instructions

Create a function that takes a list of integers and returns the sum of all the integers that have an even index, multiplied by the integer at the last index.

For example:

[2, 3, 4, 5] ➞ 30
(2 + 4) * 5 ➞ 30

[1, 4, 5, 6, 7, 2, 3] ➞ 48
(1 + 5 + 7 + 3) * 3 ➞ 48

Examples

even_last([]) ➞ 0

even_last([1, 3, 3, 1, 10]) ➞ 140

even_last([-11, 3, 3, 1, 10]) ➞ 20

Notes

If the list is empty, return 0.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find Unique Number in List