Re: please i need explanation

Discussion in 'Python' started by Karim, Jan 11, 2013.

  1. Karim

    Karim Guest

    On 11/01/2013 16:35, 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
     
    Karim, Jan 11, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    124
    Walter Hurry
    Jan 13, 2013
  2. K. Elo

    Re: please i need explanation

    K. Elo, Jan 11, 2013, in forum: Python
    Replies:
    0
    Views:
    128
    K. Elo
    Jan 11, 2013
  3. Vincent Vande Vyvre

    Re: please i need explanation

    Vincent Vande Vyvre, Jan 11, 2013, in forum: Python
    Replies:
    0
    Views:
    107
    Vincent Vande Vyvre
    Jan 11, 2013
  4. Jussi Piitulainen

    Re: please i need explanation

    Jussi Piitulainen, Jan 11, 2013, in forum: Python
    Replies:
    2
    Views:
    121
  5. Karim

    Re: please i need explanation

    Karim, Jan 11, 2013, in forum: Python
    Replies:
    0
    Views:
    110
    Karim
    Jan 11, 2013
Loading...

Share This Page