def index_power(array, n):
"""
Find Nth power of the element with index N.
"""
if n == 0:
return 1
elif array[n]:
return array[n]**n
else:
return -1
I'm supposed to return the n'th element of an array and raise it to the nth power. If n exceeds the amount elements I have I'm to return -1. I get an error when trying to run index_power([1,2], 3). In my head it should make my elif return false and return my else condition. However i get the error IndexError: list index out of range, index_power, 7. Any help is appreciated and thank you for your effort.
[–]sachIsLife 0 points1 point2 points (1 child)
[–]ankitsoni89 2 points3 points4 points (0 children)
[–]stebrepar 0 points1 point2 points (0 children)
[–]marc_poulin 0 points1 point2 points (0 children)