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


Groups > comp.lang.python > #87834

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!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'algorithm': 0.04; 'elif': 0.05; 'subject:missing': 0.07; 'worse': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'suggest': 0.14; '24,': 0.16; 'expecting': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'loop.': 0.16; 'normally,': 0.16; 'rewriting': 0.16; 'sequence,': 0.16; "someone's": 0.16; 'elements': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'example': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'diverse': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; '[1]': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'subject:what': 0.31; 'regular': 0.32; 'run': 0.32; 'running': 0.33; 'could': 0.34; 'display': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'doing': 0.36; 'should': 0.36; 'skip:[ 10': 0.38; 'till': 0.61; 'entire': 0.61; "you're": 0.61; 'reach': 0.63; 'such': 0.63; 'more': 0.64; 'note:': 0.66; 'mar': 0.68; 'to,': 0.72; '2015': 0.84; 'safer': 0.84; 'wanted,': 0.84; 'fibonacci': 0.91; 'inefficient': 0.91; 'to:none': 0.92
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:cc :content-type; bh=P8mrUFVJ8g7R5xTcVcF23foOV0jdWMO2m0qWeemUr/c=; b=guQCK5OZulN5g59UoszIo7V50x9BdHInhMEbLwtYigCloP2uCoUZXK0/TVkIkOvmVK gGn2/6LOGwmF4iTx7VPDfvuyB8l9+eerF9DQw1RwEz6zcs9il5R1rbNdQwQcwIbadTOu i+n1nvzz+HxzVXz25jU71lB5KE4J0QMSMkS7d/MVAWLXu3znkSvkxFtilp2QNpopQf7Y ePjaJIRsV2eaBvzjPi0DuQpRr/qW9pZuAcxbKgAxKr19T/L5BVA5+vU8YlXsfZxqI2C7 nGhiS9VZva1lwYmG5GT8qqvmnI32o0e2i0YLum9bHKG7I+7Fjw6Fcs4aU/i4/UvRnCpW 7NLw==
MIME-Version 1.0
X-Received by 10.107.160.212 with SMTP id j203mr26044426ioe.43.1427127408069; Mon, 23 Mar 2015 09:16:48 -0700 (PDT)
In-Reply-To <CACT3xuVF-MOVQK5wSorRSAfpAQEXvS7QsqarACVZKXsQ0bxzpQ@mail.gmail.com>
References <CACT3xuVF-MOVQK5wSorRSAfpAQEXvS7QsqarACVZKXsQ0bxzpQ@mail.gmail.com>
Date Tue, 24 Mar 2015 03:16:48 +1100
Subject Re: fibonacci series what Iam is missing ?
From Chris Angelico <rosuav@gmail.com>
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.72.1427127417.10327.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427127417 news.xs4all.nl 2927 [2001:888:2000:d::a6]:60834
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87834

Show key headers only | View raw


On Tue, Mar 24, 2015 at 3:01 AM, Ganesh Pal <ganesh1pal@gmail.com> wrote:
> Hello team ,
>
>
> [root@localhost Python]# cat  fibonacci-Sequence-3.py
>
> ## Example 2: Using recursion
> def fib(n):
>     if n == 0:
>         return 0
>     elif n == 1:
>         return 1
>     else:
>         return fib(n-1) + fib(n-2)
> print fib(5)
>
> # python  fibonacci-Sequence-3.py
> 5
>
> what Iam I missing in the program , I was expecting 0,1,1,2,3 ?

What you're doing is printing out the fifth Fibonacci number. So there
are three things to note:

1) To display the entire sequence, you will need some sort of loop.
2) Your algorithm is about as hopelessly inefficient as it could
possibly be, barring deliberate intent. [1]
3) You are running Python 2.x; unless you have a good reason not to,
it's better to use Python 3.
4) You're running as root. Normally, something like this should be run
as a regular user - it's safer that way.

Err, *amongst* the things to note are such diverse elements as...
etcetera, etcetera. Ahem.

I would suggest rewriting this as a much more straight-forward loop;
begin at the beginning, go on till you reach the point you wanted,
then stop.

ChrisA

[1] Cue the demonstration of a worse version from someone's student?

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


Thread

Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 03:16 +1100
  Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 11:19 +1100
    Re: fibonacci series what Iam is missing ? Dave Angel <davea@davea.name> - 2015-03-23 20:42 -0400
    Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 11:56 +1100
    Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 11:59 +1100
      Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 12:52 +1100
        Re: fibonacci series what Iam is missing ? Rustom Mody <rustompmody@gmail.com> - 2015-03-23 19:23 -0700
        Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 14:03 +1100
          Re: fibonacci series what Iam is missing ? Rustom Mody <rustompmody@gmail.com> - 2015-03-23 20:30 -0700
          Re: fibonacci series what Iam is missing ? Rustom Mody <rustompmody@gmail.com> - 2015-03-23 21:13 -0700

csiph-web