# Re: please i need explanation

Discussion in 'Python' started by Steve Simmons, Jan 11, 2013.

1. ### Steve SimmonsGuest

I read the question as "I've got this function and it does what I expect
but I don't understand the code".
On that basis...

The function creates a factorialfor the input number 'n' (i.e.
1*2*3*4.....*n)

The first 2 lines checks to see that the input is less than 2 and, if
so, returns a value of 1
The rest of the code counts down from n to 1 multiplying f by n at each
iteration.

If I guessed the right question, reply to the post for further
clarification.

Steve

On 11/01/2013 16: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.
>
Steve Simmons, Jan 11, 2013