Wednesday, 12 October 2016

Fibonacci series using while loop

n=int(input("enter no:"))
n0=1
n1=1
count=2
if n<=0:
    print("Please enter positive integer")
elif n==1:
    print("fibonacci series:",n0)
else:
    print("fibonacci series:",n0,n1,'',end='')
    while count<n:
        nth=n0+n1
        print(nth,'',end='')
        n0=n1
        n1=nth
        count+=1

No comments:

Post a Comment