This kata is from check py.checkio.org

You are given an array with positive numbers and a 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. Don't forget that the first element has the index 0.

Let's look at a few examples:

* array = [1, 2, 3, 4] and N = 2, then the result is 3^2 == 9;
* array = [1, 2, 3] and N = 3, but N is outside of the array, so the result is -1.

Difficulty: introductory

Starter code:

def index(array, n):
	

Solutions:
def index(array, n):
    try:
        return array[n]**n
    except:
        return -1

def index(array, n):
    return array[n]**n if n < len(array) else -1

def index(array, n):
    try:
        return pow(array[n],n)
    except IndexError:
        return -1

def index(array, n):
    if n < len(array):
        return (array[n])**n
    else:
        return -1

from typing import List

def index(array: List[int], n: int) -> int:
    """ Get the N-th power of the element in the array with the index N. """
    try:
        return pow(array[n], n)
    except IndexError:
        return -1

def index(array, n):
    return array[n]**n if n <= len(array) - 1 else -1

def index(array, n):
    return array[n] ** n if len(array) >= n + 1 else -1

def index(array, n):
    return -1 if n >= len(array) else array[n] ** n

def index(arr, n):
    return arr[n] ** n if n < len(arr) else -1

def index(array, n):
    return array[n] ** n if len(array) > n else -1

index = lambda a, n: -1 if len(a)<=n else a[n]**n

def index(array, n):
    if (n < len(array)):
        return pow(array[n], n)
    return -1    

import math
def index(array, n):
    if len(array) > n:
        return math.pow(array[n], n)
    else:
        return -1

def index(array, n):
    return pow(array[n], n) if n < len(array) else -1

def index(array, n):
    return array[n] ** n if n in range(len(array)) else -1

def index(array, n):
    return array[n] ** n if 0 <= n < len(array) else -1

def index(array, n):
    if n >= len(array):
            return -1
    else:
            return array[n]**n

def index(a, n):
    if (len(a)-1)<n:
        return -1
    return a[n]**n

def index(arr, n):
  try:
    return arr[n] ** n
  except:
    return -1

index = lambda a, n: a[n] ** n if n + 1 <= len(a) else -1

index = lambda a,n: -1 if n+1 > len(a) else a[n]**n 

index=lambda a,n:-(n>=len(a))or a[n]**n

index = lambda a,i : a[i]**i if len(a)-1 >= i else -1

def index(array, n):
    for idx in range(len(array)):
        if idx == n:
            return array[idx] ** n
    return -1

def index(array, n):
    if n>=len(array) or n<0:
        return -1
    else:
        return (array[n])**n

def index(array, n):
    if 0<=n<len(array):
        return pow(array[n],n)
    else:return -1

def index(array, n):
    if(n<=len(array)-1):
        array[n]=array[n]**n
        return array[n]
    else:
        return -1


def index(array, n):
    try:
        return array[n]**n
    except:
        return -1
print(index([1,2,3,4],2))

def index(array, n):
    
    if n < len(array):
        x = array[n] **n;
    else:
        x = -1;
        
    return x;

def index(array, n):
    if (len(array)-1)>=n:
        for i in range(len(array)):
            return array[n]**n
    else:
        return -1

def index(array: list, n: int) -> int:
    """ This function find the N-th power of the element in the array with the index N. """
    for k, i in enumerate(range(len(array))):
        if i == n:
            return (array[i] ** n)
    return -1

def index(array, n):
    if array==[]:
        return -1
    if len(array)>n:
        return array[n]**n
    else: return -1


def index(array, n):
        if n+1<len(array):
            return (array[n])**n
        else:
            if n+1>len(array):
                return -1
            else:
                return (array[n])**n


def index(array: list, n: int) -> int:
    return array[n]**n if n < len(array) else -1

def index(array, n):
    if (len(array)<n+1):
        return -1
    else:
        return pow(array[n],n)

def index(array, n):
    try: 
        return array[n] ** n
    except:
        return -1
        

print(index ([1, 2, 3, 4], 2  ))    

print(index([1, 3, 10, 100],3))

print(index([1, 3, 10, 100],10))

import math
def index(array, n):
    if(len(array)==0):
        return -1
    for i in array:
        if (n>len(array)-1):
            return -1
        if i is array[n]:
            return(math.pow(i,n))

import math

def index(array, n):
    for i in range(len(array)):
        if i == n:
            return array[i] ** n
    return -1

def index(array, n):
    if len(array) <= n :
        return -1 
    else:
        nth = array[n]
        nth_sq = nth ** n
    return nth_sq


def index(array, n):
    if len(array) <= n:
        return -1
    for i in range(len(array)):
        if i == n:
            return array[i] ** n


def index(array, n):
    while n >= len(array):
        return -1
    else:
        return array[n] ** n

index = lambda l,n:l[n]**n if n<len(l) else -1

def index(array, n):

    for i, val in enumerate(array):
        if n == i:
            return  val ** n
    else:
        return -1
        


def index(array, n):
    result = 1
    if n > len(array) - 1 :
        return -1 
    else:
        for index in range(n):
            result = result * array[n]
    return result


def index(array, n):
    if n<len(array):
        return int(array[n]**n)
    if n>=len(array):
        return -1


def index(array, n=0):
    if n > len(array)-1:
        return -1
    else:
        return array[n]**n



def index(array, n):
    print((len(array)))
    if n >= len(array):
        return(-1)
        print((-1))
    else:
        return(array[n]**n)


index = lambda a, n: -1 if n >= len(a) else a[n] ** n

def index(array, n):
    try:   
        x = array[n]
    except IndexError:
        return -1
    y = x**n
    return y


def index(array, n):
    x=len(array)
    if n > x - 1:
        return -1
    else:
        return array[n] ** n

def index(array, n):
    return pow(array[n],n) if n <= len(array)-1 else -1

def index(array, n):
    if len(array) < n+1:
        return -1
    elif len(array) >= n+1:
        number = array[abs(n)]
        return number ** n
    else:
        pass

def index(array, n):
    if n >= len(array): # Here, the nth index will be outside the array.
        return -1
    else:
        return array[n] ** n

def index(array, n):
    
    try:
        if (n - 1) > len(array):
            return -1
        else:
            return array[n] ** n

    except IndexError:
        return -1

def index(array, n):
    if len(array)-1<n:
        a=-1
        return(a)
    else:
        return(array[n]**n)

def index(array, n):
    for idx, i in enumerate(array):
        if idx == n:
            x = array[idx] ** n
            return x
    else:
        return -1

def index(array, n):
    list(array)
    if n>len(array)-1 :
      return -1
    else:
      return (array[n]**n)


def index(array, n):
    ans = 1
    if n > len(array)-1:
        return -1
    else:
        for i in range (n):
           ans *= array[n] 
        return ans

def index(array, n):
    if n < len(array):
        a = array[n]
        num = a ** n
        return num
    else:
        return -1


def index(array, n):
    if n > len(array)-1:
        return -1
    else:
        number = array[n]
        return number**n

def index(array, n):
    list(array)
    while n < len(array):
        return (array[n])**n
    else:
        return -1

def index(array, n):
    list(array)
    if n < len(array):
        return (array[n])**n
    else:
        return -1


def index(array, n):
    contar = 0
    for numero in array:
        contar = contar + 1
    if (contar) > n:
        y = array[n]
        x = y**n
        return x
    else:
        return -1

def index(array, n):
    if n < len(array):
        target = array[n]
        ans = target ** n
        
        return ans
    else:
        return -1

def index(array, n):
    dlina = len(array)
    if n <= dlina - 1:
        return(array[n]**n)
    else:
        return (-1)
    


def index(array, n):
    while True:
        try:
            return array[n] ** n 
            break
        except IndexError:
            return -1

def index(array, n):
    try:
        if len(array) >= n:
            return array[n] ** n
        else:
            return -1
    except IndexError:
        return -1


def index(array, n):
    if len(array)>n:
        a=array[n]  
        return a**n
    else: 
        return -1

index=lambda a,n:a[n]**n if n<len(a)else~0

def index(array, n):
    return array [n]**n if n <len(array) else -1

    
    '''
    if n < len(array):
        return (array[n]**n) 
    else:
        return -1
    '''

def index(array, n):
    try:
        a = array[n]**n
        return a
    except IndexError:
        return -1

def index(array, n):
    
    if len(array) > n:
        nTh = array[n]**n
    else:
        nTh = -1
    return nTh

def index(array, n):
    try:
        a = array[n]**n
        return a
    except:
        return -1


def index(array, n):
    nth_power = None
    try: nth_power = array[n]**n
    except: nth_power = -1
    return nth_power

def index(array, n):
    try:
        x = array.pop(n)
    except IndexError:
        return -1
    return x**n

def index(array, n):
    length = len(array)
    if n <= length - 1:
        return array[n]**n
    else:
        return -1

def index(array, n):
    if (n > len(array) - 1):
        return -1
    else:
        result = 1
        i = 0
        while (i < n):
            result *= array[n]
            i += 1
        return result

def index(array, n):
    if n > len(array) - 1:
        return(-1)
    elif n == 0:
        return(1)
    else:
        pw = array[n]
        i = 1
        while i !=  n:
            array[n] *= pw
            i += 1
        return(array[n])


def index(array, n):
    try:
        if n:
            index = array[n]
            return index**n
        elif n == 0:
            return 1
    except:
        return -1


def index(array, n):
    y = 0
    if n > len(array)-1:
        y = -1
    else:
        y = pow(array[n],n)
    return y

def index(array, n):
    if len(array)-1<n:
        otvet=-1
    else:
        otvet=array[n]**n
    return otvet

def index(array, n):
    print(array)
    print(n)
    if(n >= len(array)):
        return -1
    else:
        return array[n] ** n

def index(array, n):
    if n <= (len(array)-1):
        n=array[n]**n
        return n
    else:
        return (-1)

def index(array, N):
    res = 0
    uzunluk = len(array)
    if N>=uzunluk:
        return -1
    
    ussuAlinacakSayi = array[N]
    return ussuAlinacakSayi**N

def index(array, n):
    return pow(array.pop(n), n) if len(array) > n else -1

def index(array, n):
    if n >= len(array) or n < 0:
        return -1
    else:
#         if n in array:
#             return array[n] ** n
        return array[n] ** n;

def index(array, n):
    arr = len(array)
    if n >= arr:
        return -1
    return array[n]**n

def index(array, n):
    if n > -1 and n < len(array):
        product = array[n]**n    
    else:
        product = -1
        
    return product

def index(array, n):
    if n >= 0 and n < len(array):
        x = 1
        for i in range(n):
            x = x * array[n]
        return x
    else:
        return -1


def index(array, n):
    try:
        return array[n]**n
    except IndexError:
        return -1
    finally:
        pass

def index(array, n):
    for i in array :
        return pow(array[n],n) if len(array)-1 >= n else -1
    else :
        return -1

def index(array, n):
    try:
        return array[n]**n
    except:
        return -1
array=[1,3,10,100]
index(array,3)

def index(array, n):
    if n >= len(array):
        return -1
    print(array, n,"", array[n], "", array[n]**2)
    return array[n]**n

def index(array, n):
    try:
        return array[n] ** n
    except (IndexError, TypeError):
        return -1

def index(array, n):
    if len(array) - 1 < n: return - 1
    for ind, value in enumerate(array):
        if ind == n:
            return(value**n)
    





def index(array, n):
    if((len(array))-1) < n:
        return(-1)
    else:
        for i in range(len(array)):
            print((n,i))
            if (n == i):
                return(array[i]**n)
       



def index(array, n):
    return -1 if n < 0 or n > len(array)-1 else array[n]**n;


def index(array, n):
    arr = []
    for i in array:
        arr.append(pow(i, n))
    if n > len(arr) - 1:
        return -1
    return arr[n]

def index(array = [], n = 0):
    if n >= len(array):
        return -1
    else:
        return array[n]**n

def index(array, n = -1):
    if n < 0 or n > len(array)-1 or n == None:
        val = -1
        return val
    elif n <= len(array)-1:
        val = array[n]
        val = val ** n
        return val