You are given an array with positive numbers and a non-negative number N. You should find the N-th power of the element in the array with the index N. If N is outside of the array, then return -1.
def index(array, n):
selected_number = []
if n > len(array):
return -1
else:
selected_number.append(array[n])
total = selected_number[0]
return total ** n
This is the code I wrote. It does the second part correctly but when the variable n is greater the array list the output doesn't output -1 like it is supposed to. How does this not work?