Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Index Power by arek.kowalski107
import math
def index_power(array, n):
if n>len(array)-1:
print(-1)
return -1
else:
sum=pow(array[n],n)
print(sum)
return sum
index_power([1, 2, 3, 4], 2) #== 9, "Square"
index_power([1, 3, 10, 100], 3)# == 1000000, "Cube"
index_power([0, 1], 0)# == 1, "Zero power"
index_power([1, 2], 3) #== -1, "IndexError"
Oct. 22, 2016