Passed
Push — master ( a892fa...d1ecba )
by Ken M.
01:03
created

index_power   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 2
1
def index_power(array, n):
2
    # Find Nth power of the element with index N.
3
    if n > len(array) - 1:
4
        return -1
5
    else:
6
        return array[n] ** n
7
8
9
if __name__ == '__main__':  # pragma: no cover
10
    # These "asserts" using only for self-checking and not necessary for
11
    # auto-testing
12
    assert index_power([1, 2, 3, 4], 2) == 9, "Square"
13
    assert index_power([1, 3, 10, 100], 3) == 1_000_000, "Cube"
14
    assert index_power([0, 1], 0) == 1, "Zero power"
15
    assert index_power([1, 2], 3) == -1, "IndexError"
16