Calculating factorial

Olli Rajala ollir at linuxfreak.com
Fri Dec 8 11:07:35 EST 2000


On 06 Dec 2000 12:49:44 +0100, Roger Hansen <rogerha at ifi.uio.no>
wrote:

>* Raymond Hettinger
>>
>> Olli Rajala wrote:

>> > def factorial(f):
>> >     result = 1
>> >     for number in range(1, f + 1):
>> >         result = result * number
>> >     return result
>> >
>> > print factorial(10)
>> 
>> I like your version just fine.  It's simple, clear, and it work's.
>> Do consider changing line 2 to:  result = 1L so you can
>> handle fact(50).
>
>Agree! it's a nice version. But I think the recursive version is even
>clearer. 

Thanks! =)  I'm reading a tutorial by Alan Gauld and there is an
"exercise" which says that I should try to calculate factorial without
recursion so I tried and that was the result.

-- 
Olli Rajala
I think you understand my poor English much better
than my good Finnish. =)



More information about the Python-list mailing list