find the factorial of a number in python

You can find the factorial of a number in Python using either a recursive function or a loop. Here's an example using a loop:

main.py
def factorial(num):
    result = 1
    for i in range(2, num+1):
        result *= i
    return result
103 chars
6 lines

And here's an example using recursion:

main.py
def factorial(num):
    if num == 1:
        return 1
    return num * factorial(num-1)
88 chars
5 lines

Both of these functions will return the factorial of the input number.

gistlibby LogSnag