Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: please i need explanation

Reply
Thread Tools

Re: please i need explanation

 
 
Karim
Guest
Posts: n/a
 
      01-11-2013
On 11/01/2013 16:35, http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
please i need explanation kwakukwatiah@gmail.com Python 2 01-13-2013 09:08 PM
Re: please i need explanation Jussi Piitulainen Python 2 01-11-2013 04:33 PM
Re: please i need explanation Karim Python 0 01-11-2013 10:41 AM
Re: please i need explanation Vincent Vande Vyvre Python 0 01-11-2013 10:11 AM
Re: please i need explanation K. Elo Python 0 01-11-2013 09:56 AM



Advertisments