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


Groups > comp.lang.python > #87883

Re: fibonacci series what Iam is missing ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ganesh1pal@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'intermediate': 0.07; 'result,': 0.07; 'subject:missing': 0.07; 'newline': 0.09; 'trailing': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '24,': 0.16; 'comma': 0.16; 'loop.': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'topic': 0.29; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:what': 0.31; 'received:google.com': 0.35; 'add': 0.35; 'thanks': 0.36; 'list': 0.37; 'thank': 0.38; 'does': 0.39; 'removing': 0.60; 'such': 0.63; 'more': 0.64; 'mar': 0.68; '2015': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=F+kvkLzpK5Jfav74ANrlQEpt4Rusf3pRKSIma6MrxQg=; b=LbWX8U8/eyL7yEHRmiQ6f/ErnQVlnre2gOVwVnUPbWiV9auKNyJmKdW/DrnSGH4749 mFNHCJ/xbeBjimIWEzF6sdfhNx9JRtjzllBWugfeH1fSmDBcrxEyuDpXzIYk0rK2B3Um /F8NLZLuIyl1POqlHEsD2Xbtxtt3UaCd7qL7N5ogpzLQ6/E+oiHhmXBwiKW7cLgCc0bU EaoyL80TapmpgztOCzgM2wvSZB13zAwCD0CQS6DdMnzfVkJCZCwhG+X0B8j23Hic/Aks Sn6n/YjjvdqZfFj2PTObMoryLeRdafejmaukfsilvoTJnLs4GuD5QYiz9azOs39OaRAw yjkA==
MIME-Version 1.0
X-Received by 10.112.13.7 with SMTP id d7mr3639836lbc.79.1427202067082; Tue, 24 Mar 2015 06:01:07 -0700 (PDT)
In-Reply-To <5510abc9$0$13011$c3e8da3$5496439d@news.astraweb.com>
References <mailman.70.1427126512.10327.python-list@python.org> <5510abc9$0$13011$c3e8da3$5496439d@news.astraweb.com>
Date Tue, 24 Mar 2015 18:31:06 +0530
Subject Re: fibonacci series what Iam is missing ?
From Ganesh Pal <ganesh1pal@gmail.com>
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.101.1427202069.10327.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427202069 news.xs4all.nl 2914 [2001:888:2000:d::a6]:44001
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87883

Show key headers only | View raw


On Tue, Mar 24, 2015 at 5:41 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:

> Python does not automatically print all return statements. If you want it to
> print the intermediate values produced, you will need to add print before
> each return:
>
>
> py> def fib(n):
> ...     if n == 0:
> ...         result = 0
> ...     elif n == 1:
> ...         result = 1
> ...     else:
> ...         result = fib(n-1) + fib(n-2)
> ...     print result,  # trailing comma means no newline
> ...     return result
> ...
> py> fib(3)
> 1 0 1 1 2
> 2
> py> fib(5)
> 1 0 1 1 2 1 0 1 3 1 0 1 1 2 5
> 5
>
>
> If you want to print a list of Fibonnaci values, you need to call the
> function in a loop. Removing the "print result" line again, you can do
> this:
>
> py> for i in range(6):
> ...     print fib(i),
> ...
> 0 1 1 2 3 5


Thanks you Steven and others ( Dave, Chris and Terry ) , for having
such good discussion on this topic and benefiting me in more than one
way's. Thank you

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


Thread

fibonacci series what Iam is missing ? Ganesh Pal <ganesh1pal@gmail.com> - 2015-03-23 21:31 +0530
  Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 11:11 +1100
    Re: fibonacci series what Iam is missing ? Ganesh Pal <ganesh1pal@gmail.com> - 2015-03-24 18:31 +0530

csiph-web