Sunday, February 26, 2012

Python - Factorial

Description: Factorial with Python.

#!/usr/bin/env python

# dumb recursive factorial
# http://people.csail.mit.edu/pgbovine/python/tutor.html
# http://kuntoaji.blogspot.com

def factorial(n):
    if (n <= 1):
        return 1
    else:
        return n * factorial(n - 1)

if __name__ == "__main__":
    # example
    print factorial(5)

Artikel Terkait

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...