| Total Complexity | 2 |
| Total Lines | 16 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |