Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Index Power by mennadiego
def index_power(ar: list[int], n: int) -> int:
"""
You are given a list with positive integers (int) and an integer (int) N.
TODO: You should find the N-th power of the element in the list with the index N.
If N is outside of the list, then return -1.
Don't forget that the first element has the index 0.
:param ar: list - input list to compute
:param n: int - power to compute
:return: int - N-th power of the element at index N
"""
return ar[n]**n if n < len(ar) else -1
print("Example:")
print(index_power([1, 2, 3], 2))
# These "asserts" are used for self-checking
assert index_power([1, 2, 3, 4], 2) == 9
assert index_power([1, 3, 10, 100], 3) == 1000000
assert index_power([0, 1], 0) == 1
assert index_power([1, 2], 3) == -1
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 18, 2023