r/pythonhelp • • Aug 16 '22

problem with Fibonacci sequence stuck on zeros??

def series(n):
  n1 = 0
  n2 = 1
  count = 0
if n <= 0:
print("enter a posotive integer")
if n >= 0:
while count <= n:
print(n1)
      nth=n1+n2
      n2 = n1
      nth = n2
      count+=1
series(5)

2 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/Aryangupt556 Aug 16 '22

How would I fix it ?

2

u/slowlycatchiemonkey Aug 16 '22

You need to understand what your own code is doing. Print out the values of each variable for series(2) and see how they change.

1

u/Aryangupt556 Aug 16 '22

I see so it’s only printing n1 and n2 with the number I implemented

1

u/Aryangupt556 Aug 17 '22

Update : fixed dumb mistake what I had to do was n1=n2 and nth=n2 and the whole thing worked can’t believe how a little mistake can impact the whole code 🤦🤦