Return the Nth Even Number

The input will not be 0.

Source: codewars | Difficulty: EASY
Tags: Mathematics

Ad-hoc

Starter code: def nth_even(n):
	

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


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


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


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


def nth_even(n):
	if n == 0:
		print('zero nie jest odd ani even')
	return int(2 * n - 2)


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 ~-n << 1


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


nth_even = lambda n: n - 1 << 1


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


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


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


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


def nth_even(n):
	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):
	a = range(0, n * 2, 2)
	return a[-1]


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


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):
	for l in range(0, 2 * n):
		return n * 2 - 2


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 == 3:
		return 4
	else:
		return n // 2 * 2 if n < 3 else n * 2 - 2


def nth_even(n):
	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')
	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


nth_even = lambda x: x - 1 << 1


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


def nth_even(n):
	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 range(0, 10 ** 10, 2)[n - 1]


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


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


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


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


def nth_even(n):
	return abs(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):
	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)
print(nth_even(3))


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


nth_even = lambda n: n * 2 - 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