In mathematics, the factorial of integer 'n' is written as 'n!'.
It is equal to the product of n and every integer preceding it.
For example: **5! = 1 x 2 x 3 x 4 x 5 = 120**

Your mission is simple: write a function that takes an integer 'n' and returns 'n!'.

You are guaranteed an integer argument. For any values outside the positive range, return `null`, `nil` or `None` .

**Note:** 0! is always equal to 1. Negative values should return null; 

For more on Factorials : http://en.wikipedia.org/wiki/Factorial

Source: codewars | Difficulty: EASY
Tags: Mathematics

Complete search

Starter code: def factorial(n):
	

Solutions:
import math

def factorial(n):
	if n < 0:
		return None
	return math.factorial(n)


def factorial(n):
	if n <= 1:
		if n < 0:
			return None
		else:
			return 1
	return n * factorial(n - 1)


import math

def factorial(n):
	try:
		return math.factorial(n)
	except ValueError:
		return None


def factorial(n):
	if n > 0:
		return reduce(lambda x, y: x * y, range(1, n + 1))
	if n < 0:
		return None
	return 1


def factorial(n):
	if n < 0:
		return None
	elif n == 0:
		return 1
	else:
		factorial = 1
		for val in xrange(1, n + 1):
			factorial *= val
		return factorial


from math import factorial as f
factorial = lambda x: f(x) if x > -1 else None


from operator import mul
from functools import reduce

def factorial(n):
	if n < 0:
		return None
	return reduce(mul, range(1, n + 1), 1)


factorial = lambda n: 1 if 0 <= n <= 1 else n * factorial(n - 1) if n > 0 else None