Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Index Power by dm.palczak
def index_power(array, n):
if n == 0:
return 1
else:
if n >= len (array):
return -1
else:
return array[n]**n
def test_function():
assert index_power([1, 2, 3, 4], 2) == 9, "Square"
assert index_power([1, 3, 10, 100], 3) == 1000000, "Cube"
assert index_power([0, 1], 0) == 1, "Zero power"
assert index_power([1, 2], 3) == -1, "IndexError"
Dec. 4, 2016