Minggu, 26 Februari 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

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...