# Computes n!, or the product of the integers 1 through n. # pre : n >= 0 def factorial(n): if n < 0: raise ValueError("n must be greater or equal to 0") product = 1 for i in range(2, n + 1): product *= i return product def main(): for i in range(0, 11): print(str(i) + "! =", factorial(i)) print(factorial(-1)) # produce an error main()