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


Groups > comp.lang.python > #36640

Re: please i need explanation

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <square.steve@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.104
X-Spam-Level *
X-Spam-Evidence '*H*': 0.79; '*S*': 0.00; "'n'": 0.09; '(instead': 0.09; 'explanation': 0.09; 'friday,': 0.09; 'def': 0.10; 'steve': 0.13; 'iteration.': 0.16; 'wrote:': 0.17; 'message-----': 0.17; 'subject:need': 0.17; 'creates': 0.18; 'input': 0.18; 'cc:2**0': 0.23; 'work.': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'question': 0.27; 'subject:please': 0.27; 'lines': 0.28; 'rest': 0.28; 'post': 0.28; 'maybe': 0.29; 'checks': 0.30; 'function': 0.30; 'expect': 0.31; 'code': 0.31; 'skip:- 10': 0.32; '11,': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'so,': 0.35; 'there': 0.35; 'subject:': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; '(i.e.': 0.36; 'totally': 0.36; 'email addr:python.org': 0.36; 'should': 0.36; 'does': 0.37; 'why': 0.37; 'sent:': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'further': 0.61; 'first': 0.61; 'email name:python-list': 0.62; 'different': 0.63; 'email addr:gmail.com': 0.63; 'reply': 0.66; 'header:Reply-To:1': 0.68; 'below.': 0.68; 'stated': 0.69; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:gmail.com': 0.79; 'counts': 0.81; '2013': 0.84; 'guessed': 0.84; 'multiplying': 0.84; 'don\xe2\x80\x99t': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:reply-to:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=V8Fgd0hzZcaOWbt8gfy8PAWaJtUiiHKiK+XKtCoaQtk=; b=Z96AcG7rzHyj5LMQkgQVh10y6x8yuFzETAAcKC89l5Wmn8P5pxXUNMkBwis21EuFBP 67BS5Ewzj6IPYfWlX7M2pWxA/JRPAjTiq1JU+dZWgaRJmiLyIyw08Bg58c4knlv29VUe DINz7PAKTvimoefilULblHknWliQkbdgijCo/tddKPwgvbBnVQpdE7cLfrkDnWiY611x +VuzedBS0SSjJyX9Y6db/GsC47y1lLMx4aY0txZk8W970wVIWqfBV1OmFDskH5wTUXN6 /93JczLfTuNNqQGV0BYoeM6SDoWSukk+Qcuy27iIYsaSse9Sj84lLASsnCZOuKNBP9ce OW6g==
X-Received by 10.180.77.68 with SMTP id q4mr615375wiw.10.1357933087273; Fri, 11 Jan 2013 11:38:07 -0800 (PST)
Date Fri, 11 Jan 2013 19:38:06 +0000
From Steve Simmons <square.steve@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: please i need explanation
References <2FB5A66FD91D456BBDFCC0AE25760392@favour> <50EFE1C3.5000303@nic.fi> <E34A7B5E52A64FEAA32CB66A8CA7AC7A@favour>
In-Reply-To <E34A7B5E52A64FEAA32CB66A8CA7AC7A@favour>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To square.steve@gmail.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.411.1357933095.2939.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357933095 news.xs4all.nl 6909 [2001:888:2000:d::a6]:57148
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36640

Show key headers only | View raw


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, kwakukwatiah@gmail.com wrote:
>
>
> -----Original Message----- From: K. Elo
> Sent: Friday, January 11, 2013 3:56 AM
> To: python-list@python.org
> 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, kwakukwatiah@gmail.com 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.
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: please i need explanation Steve Simmons <square.steve@gmail.com> - 2013-01-11 19:38 +0000

csiph-web