Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Index Power solution in Clear category for Index Power by konradgolinski
def index_power(array, n):
"""
Find Nth power of the element with index N.
"""
if(len(array) > n):
if(array[n]):
if (len(array) > 0 and len(array) <= 10 and n>=0):
if array[n]:
if(n == 0 and array[n] == 0):
return 1
else:
y = int(array[n])**n
return y
else:
return 1
else:
return -1
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
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, "Nieoznaczony"
assert index_power([1, 2], 3) == -1, "IndexError"
Nov. 14, 2016