User manual for module 'factorial' ================================== The n-th factorial is defined mathematically as: n! = (n)(n-1)(n-2)...(3)(2)(1) (This definition really only makes sense if n is a positive whole number.) The factorial is useful, for instance, in combinatorics: n! tells you the number of permutations (unique orderings) of a set of n different objects. This module provides a single function, factorial(n), which computes the n-th factorial. The function takes exactly one parameter, which must be a positive number (zero is okay). To use the function, first import it: >>> from factorialtest import factorial Now we can calculate, say, 6! = (6)(5)(4)(3)(2)(1): >>> factorial(6) 720 Zero-factorial is defined as 1: >>> factorial(0) 1 Here are the first ten factorials, from 0! up to 9!: >>> [factorial(n) for n in range(10)] [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880] The factorials get really big, really fast: >>> factorial(30) 265252859812191058636308480000000 It's okay to give the factorial function a float, as long as it is a whole number: >>> factorial(30.0) 265252859812191058636308480000000 >>> factorial(30.1) Traceback (most recent call last): ... ValueError: n must be exact integer It also doesn't make sense to take the factorial of a negative number: >>> factorial(-1) Traceback (most recent call last): ... ValueError: n must be >= 0 There are also limits on how big of a factorial this function can compute: >>> factorial(1e100) Traceback (most recent call last): ... OverflowError: n too large Have fun computing factorials! For more reading, check out Stirling's approximation for large factorials