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


Groups > comp.lang.python > #87883

Re: fibonacci series what Iam is missing ?

References <mailman.70.1427126512.10327.python-list@python.org> <5510abc9$0$13011$c3e8da3$5496439d@news.astraweb.com>
Date 2015-03-24 18:31 +0530
Subject Re: fibonacci series what Iam is missing ?
From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.101.1427202069.10327.python-list@python.org> (permalink)

Show all headers | 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