Re: please i need explanation

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

  1. Karim

    Karim Guest

    On 11/01/2013 17:33, wrote:
    >
    >
    > -----Original Message----- From: K. Elo
    > Sent: Friday, January 11, 2013 3:56 AM
    > To:
    > Subject: Re: please i need explanation
    >
    > Hi!
    >
    > Since there is no stated question, I need to guess:
    >
    > n -= 1 (instead of "f -= 1")
    >
    > should work.
    >
    > Or maybe the question was a totally different one...
    >
    > -Kimmo
    >
    > 11.01.2013 17:35, wrote:
    >> def factorial(n):
    >> if n<2:
    >> return 1
    >> f = 1
    >> while n>= 2:
    >> f *= n
    >> f -= 1
    >> return f
    >>
    >>
    >>

    > please it works.but don’t get why the return 1 and the code below.
    >

    factorial or n! = n*(n-1)*(n-2).... for n > 1. For n = 0, 1 the
    factorial is 1 the reason for the 'return 1'.

    f *= n <=> f = f* n
    f -= 1 <=> f = f - 1 but sure this is not correct as Kimmo said n = n -
    1 or n -= 1

    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:
    132
    Walter Hurry
    Jan 13, 2013
  2. K. Elo

    Re: please i need explanation

    K. Elo, Jan 11, 2013, in forum: Python
    Replies:
    0
    Views:
    132
    K. Elo
    Jan 11, 2013
  3. Karim

    Re: please i need explanation

    Karim, Jan 11, 2013, in forum: Python
    Replies:
    0
    Views:
    134
    Karim
    Jan 11, 2013
  4. Vincent Vande Vyvre

    Re: please i need explanation

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

    Re: please i need explanation

    Jussi Piitulainen, Jan 11, 2013, in forum: Python
    Replies:
    2
    Views:
    127
Loading...

Share This Page