[Tutor] factorial
TJ
tgrimes@teleport.com
Sun May 11 22:02:02 2003
>Maybe I got the syntax wrong on Danny's approximation version, but the way I
>did it it's way off.
>
>Can anyone tell me if I got the syntax wrong or if the function actually
>doesn't work well?
>def apFactorial(n): #this should be equivalent to Danny's
> return ((math.sqrt(2 * math.pi)) * (n**(n+1/2)) * (math.exp(-n)))
I played with this a little. Your syntax looks okay to me except you
are doing an integer division in this term: (n**(n+1/2)) This is not
what you want. Change this term to (n**(n+1/2.0)) or even
(n**(n+0.5)) and you will get better results.
My results were:
Approximate function: 3598695
Recursive function: 3628800
Iterative function: 3628800
TJ