Return the Nth Even Number

The input will not be 0.

Difficulty: introductory

Starter code:

def nth_even(n):
	

Solutions:
def nth_even(n):
    return 2 * (n - 1);

def nth_even(n):
    return n * 2 - 2

def nth_even(n):
    return (n-1)*2;

nth_even = lambda x: 2 * (x - 1)

nth_even = lambda n: (n - 1) * 2


def nth_even(n):
    '''import numpy as np
    np.even1=0
    #even1 = long(even1)
    for i in range(n):
        np.even1 = np.even1+2
        n=n-1'''
  
    return n*2-2


def nth_even(n):
  if n == 0:
    print("zero nie jest odd ani even")
  return int(2 * n - 2)
  
# przeblysk- pokombinowalem i sam wymyslilem wzor na nth number :)))


def nth_even(n):
    maListe = range(n * 2)
    for elem in maListe[::-1]:
        if elem % 2 == 0:
            return elem

def nth_even(n):
    number = n*2 - 2
    return number

def nth_even(n):
    return 2 * n - 2

def nth_even(n):
    return ~-n<<1

def nth_even(n):
    x = range(0, 100000000000, 2)
    
    return x[n-1]

nth_even = lambda n:(n<<1)-2

nth_even = lambda n: n - 1 << 1

#enum = []
#for n in l:
#        if n % 2 == 0:
#            enum.append(n)
def nth_even(n):
    x = 0
    x = n
    x = x * 2 - 2
    return x
#    i = -1
#    x = 0
#    y = 0
#    j = -1
#    enum = []
#    while j < 6500000:
#        j += 1
#        if j & 1 == 0:
#            enum.append(j)        
#    while x < n:
#        i = i + 1
#        if i & 1 == 0:
#            x = x + 1
#            y = i
#            continue
#    return y;    


def nth_even(n):
    return(int(n*2)-2)


def nth_even(n): return (n-1)*2    # So simple :D

def nth_even(n):
    if n == 1:
      return 0
      
    else:
      return n + (n - 2)

def nth_even(n):
    return 2 * ~-n

def nth_even(n):
    return 2*(n-1)
#     arr = []
#     for i in range(0,2*n+1):
#         if i%2==0:
#             arr.append(i)
#     return arr[n-1]
# 0, 2, 4, 6, 8, 10
# 2*(n-1)


def nth_even(n):
    return (n - 1) * 2 if n else 0

def nth_even(n):
    #your code here
    x=(n-1)*2
    return(x)

def nth_even(n):
    n1= n * 2   
    return (n1-2)

def nth_even(n):
#     Q = [x for x in range(n*8) if x % 2 == 0]
#     return Q[n-1]
    if n == 1:
        return 0
    elif n >= 2:
        return n+(n-2)


def nth_even(n):
    return range(0, 1000000000000, 2)[n -1]

def nth_even(n):
    return 2 * (n - 1)
    # assume the result is part of a list of multiples of 2. The nth element is than the index of that list


def nth_even(n):
    a = range(0,n*2, 2)
    return a[-1]

def nth_even(num):
    return 2 * (num-1)

def nth_even(n):
    nth = n - 1
    return nth * 2

def nth_even(n):
    return range(0, 2*n+1, 2)[n-1]

def nth_even(n):
    s = n-1
    return s*2


def nth_even(n):
    result = range(n * 2)
    for elem in result[::-1]:
        if elem % 2 == 0:
            return elem

import unittest


def nth_even(n):
    return (n - 1) * 2
    
    
class TestNthEven(unittest.TestCase):
    def test_should_0_when_given_n_is_1(self):
        n = 1
        actual = nth_even(n)
        self.assertEqual(actual, 0)

    def test_should_4_when_given_n_is_3(self):
        n = 3
        actual = nth_even(n)
        self.assertEqual(actual, 4)


def nth_even(n):
    return [i for i in range(n * 2 - 50, n * 2, 2)][-1]

def nth_even(n):
    if n <= 1:
        return 0
    elif n == 2:
        return n
    else:
        return n * 2 - 2 

def nth_even(n):
    for l in range(0,2*n):
        return n*2-2

def nth_even(n):
    return 0 if n==1 else (n-1)*2

def nth_even(n):
    return 2 * (n - 1)


# def nth_even(n):
#     return n * 2 - 2


# def nth_even(n):
#     return (n-1)*2


def nth_even(n):
    return n*2-1 if (n*2-1) % 2 == 0 else n*2-2

def nth_even(n):
    return (0 + n * 2) -2


def nth_even(n):
    return (n-1)*2# here

def nth_even(n):
    return (n * 2) -2 
#    if n = 0:
 #       return 0
  #  elif n == 1:
   #     return 0
#    elif n == 2:
 #       return 2
  #  elif n == 3:
   #     return 3
 #   elif n 4:
  #      return 6
   # elif


def nth_even(n):
    a1 = 0
    d = 2 
    return a1+d*(n-1)

def nth_even(n):
    a = range(0,10000000000)
    return a[n*2-2]

def nth_even(n):
    if n == 1:
        return 0
    if n == 2:
        return 2
    else:
        return 2*n-2

def nth_even(n):
    #your code here
    if n<1:
        return 0
    else:
        return 2*(n-1)

def nth_even(n):
    return range(0,2*n,2)[n-1]

def nth_even(n):
    if n == 3:
        return 4
    else:
        return (n//2) * 2 if n < 3 else (n * 2) - 2


def nth_even(n):
    #ensuring we have the right input
    if not isinstance(n, int):
         raise TypeError("sorry, only intergers allowed - try again") 
    if n <1:
        raise ValueError("sorry, enter a number larger than 0")

    #this is the formula for showing the nth even number
    return n*2-2

def nth_even(n):
    return range(n*2)[-2]

def nth_even(n):
    rs = 0
    rs = n * 2 - 2
    return rs


def nth_even(n):
    return 0 if n < 2 else n if n < 3 else n*2-2

def nth_even(n):
    return (n - 1) * 2
    #return lst[n]


def nth_even(n):
  
  #l =[i for i in range (0,n*2,2)]; 
  # return l[-1:n]                  
   return n*2-2

#print(nth_even(200))


def nth_even(n):
  return 0 if n < 1 else 2 * (n-1)

def nth_even(n):
    #new_lst = []
    #for i in range(2*n):
     # if i% 2 == 0:
       # new_lst.append(i)
    #return(new_lst[-1])
    return (2 * n) - 2  

def nth_even(n):
    if n < 2: return 0
    else: return n*2-2

nth_even = lambda x:(x-1)<<1

def nth_even(n):
    #your code here
  return ((n*2)-2)
  
  
nth_even(5)


def nth_even(n):
    #your code here
    if(n==1):
        return 0
    if(n==2):
        return 2
    if(n>2):
        m=n-2
        sum= n+m
        return sum

def nth_even(n):
    return (n*2)-2 if n!=1 else 0

def nth_even(n):
    return (n-1)*2+0

def nth_even(n):
# nthEven(1) //=> 0, the first even number is 0
# nthEven(3) //=> 4, the 3rd even number is 4 (0, 2, 4)

# nthEven(100) //=> 198
# nthEven(1298734) //=> 2597466
    return 2*(n-1)

def nth_even(n):
    return range(0,10**10,2)[n-1]

def nth_even(n):
    return 0 + 2*n - 2

def nth_even(n):
    return list(range(0, n*2+1, 2))[n-1]
    #Makes a list of numbers that start at zero, increment
    #by 2, and stops at n*2. The index is one less than
    #the position requested.


def nth_even(n):
    return n*3 - n - 2

def nth_even(n):
    x = n * 2 - 1
    return x if x % 2 == 0 else x -1

def nth_even(n):
    #othr way to find even
    return (2*n)-2

def nth_even(n):
    #your code here
    # (0, 2, 4, 6, 8)
    # (1, 2, 3, 4, 5)
    return 2 * n - 2 

def nth_even(n):
    #your code her
    return 2*n-2

def nth_even(n):
    s=(2*n)-2
    return s

def nth_even(n):
    #your code here
    array =list(range(0,n*2,2))
    if array[n-1]%2==0:
        return array[n-1]
         
          
    
            


def nth_even(n):
    if n == 1: return 0
    elif n == 2: return 2
    return n*2-2


def nth_even(n):
    return abs(n*2 - 2)

def nth_even(n):
    
    
    return 0 if n == 0 else n * 2 -2
    
   


def nth_even(n):
    #even... 0,2,4,6,8,10,12,14,16,18,20...
    return (n*2)-2

def nth_even(n):
    return max((n-1) * 2, 0)

def nth_even(n):
    arr = range(0, n * 2, 2)
    return arr[len(arr) - 1]

def nth_even(n):
    even = 2*(n-1)
    return even

def nth_even(n):
    if n==1:
        return 0
    if n==2:
        return 2
    if n==3:
        return 4
    else:
        return n*2-2


def nth_even(n):
    return 2*(n-1) # Arithmetic sequence (arithmetic progression)

def nth_even(n):
    return 2 * (n - 1)
print(nth_even(3))

def nth_even(n):
    if n * 2 % 2 == 0:
        return (n * 2) - 2
    else:
        return (n * 2) - 1 

def nth_even(n):
    
    for i in range(n-1,n):
        return i*2
        
        
        
    #your code her


def nth_even(n):
    number = (n-1)*2
    return number
    
    
  
    


def nth_even(n):
    if n == 1:
        return 0
    elif n > 1:
        return n*2-2

def nth_even(n):
    evenNum = (n - 1) * 2
    return evenNum


def nth_even(n):
   return (n-1)*2 #Airthmetic Progression

def nth_even(n):
    result = n * 2
    return result - 2

def nth_even(n):
    #your code here
    #return (list(range(0,n*2,2))[n-1])
      return n*2-2

nth_even = lambda n: n*2 -2
# def nth_even(n):
#     #your code here


def nth_even(n):
    '''
    input: n, positive integer
    output: n-th even number (0 is first, 2 is second, 4 is third etc.)
    '''
    return (n - 1) * 2

def nth_even(n):
    result = 2 * n - 2
    return result

def nth_even(n):
    n = (n-1)*2
    return n

def nth_even(n):
    return 4 *(n-((n+1)/2))


def nth_even(n):
    if (n != 0):
        return (2 * n - 2)

def nth_even(n):
    even = 2 * n - 2
    return even


def nth_even(n):
    if n>=3:
        return (2*n)-2
    
    if n==2:
        return 2
    
    if n==1:
        return 0