# Returns the factorial of a number def factorial(x): if x < 0: raise ValueError("Factorial is only defined for x >= 0") y = 1 while x >= 2: y *= x x -= 1 return y