Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fibonacci
#1
Hi Guys,

I am a Python beginner and trying to write a code for Fibonacci sequence.
I wrote the following code and got a following result: [1, 1, 3, 5, 8, 13, 21, 34, 55, 89]
I was expecting "2" to be included between second and third number...
Can anyone explain what is wrong with this code?
Thank you!
Yasunaga

def Fibo(n):
    a,b=1,1
    if n==0:
        return a
    elif n==1:
        return b
    else:
        for x in range (n):
            a,b = b, a+b
        return b
Fibonacci=list([Fibo(n) for n in range(0,10)])
print(Fibonacci)
Yoriz write May-15-2021, 11:28 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Fibonacci - by Yasunaga - May-15-2021, 11:15 AM
RE: Fibonacci - by Yoriz - May-15-2021, 11:51 AM
RE: Fibonacci - by Yasunaga - May-15-2021, 02:00 PM
RE: Fibonacci - by snippsat - May-15-2021, 01:49 PM
RE: Fibonacci - by jefsummers - May-15-2021, 02:07 PM
RE: Fibonacci - by Yasunaga - May-16-2021, 02:26 AM
RE: Fibonacci - by jefsummers - May-15-2021, 02:08 PM
RE: Fibonacci - by csr - May-16-2021, 02:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  fibonacci ***Time limit exceeded*** frequency 18 10,489 Nov-29-2018, 09:03 PM
Last Post: frequency
  Fibonacci sequence Darbandiman123 2 2,753 Sep-26-2018, 02:32 PM
Last Post: Darbandiman123
  Help debug my fibonacci implementation dineshpabbi10 6 4,084 May-16-2018, 12:12 PM
Last Post: dineshpabbi10
  Fibonacci Sequence on Turtle JRod 9 12,649 Feb-06-2017, 01:24 PM
Last Post: JRod

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020