def fact(x):
    if x == 1: return 1  # don't forget this
    else: return x * fact(x - 1)

print fact(5)


> Factorial algorithm is a very simple and common algorithm, and it's
> one of the most basic of all recursive algorithm
> def fact(x):
>     return x * fact(x - 1)
>
> That recursive function is very close to the basic definition of
> factorials, that is
> x! = x * (x - 1)!
>
> If however, you expected x to be a real (float) value, you'd better
> consider the gamma function as Mark Dickinson pointed out. Wikipedia
> is a good start to create your gamma function:
> http://en.wikipedia.org/wiki/Factorial
> http://en.wikipedia.org/wiki/Gamma_function
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to