Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36612 > unrolled thread

Re: please i need explanation

Started byKarim <kliateni@gmail.com>
First post2013-01-11 10:59 +0100
Last post2013-01-11 10:59 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: please i need explanation Karim <kliateni@gmail.com> - 2013-01-11 10:59 +0100

#36612 — Re: please i need explanation

FromKarim <kliateni@gmail.com>
Date2013-01-11 10:59 +0100
SubjectRe: please i need explanation
Message-ID<mailman.391.1357898744.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On 11/01/2013 16:35, kwakukwatiah@gmail.com wrote:
> def factorial(n):
>     if n<2:
>              return 1
>     f = 1
>     while n>= 2:
>         f *= n
>         f -= 1
>     return f
>
>
What explanation this a function representing the math factorial.

You provide a parameter n:

if n est lower than 2 the factorial is 1 (return by the function).
in other case you multiply previous factoriel value by n (f *= n <=> f = 
f *n).
And you decrement n by 1 (f -=1 <=> f = f - 1).
This gives n*(n-)*(n-2).... general formula for factorial.

Regards
Karim

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web