from functools import reduce
import operator


def factorial(num):
    """Factorial function."""
    if num != int(num):
        raise ValueError("cannot calculate factorial of %s: number must be an integer" % num)
    elif num < 0:
        raise ValueError("cannot calculate factorial of %s: number must be non-negative" % num)
    else:
        return reduce(operator.mul, range(2, int(num) + 1), 1)