Fibonacci series in Python - Coder's point

Thursday, May 30, 2019

Fibonacci series in Python

 n = int(input("Enter number of terms:"))  
 # first two terms  
 n1 = 0  
 n2 = 1  
 count = 0  
 if n <= 0:  
   print("Please enter a positive integer")  
 elif n == 1:  
    print(n1)  
 else:  
   print("Fibonacci series:")  
   while count < n:  
     print(n1,end='')  
     n3 = n1 + n2  
     # update values  
     n1=n2  
     n2=n3  
     count += 1  
OUTPUT:
Enter number of terms : 6
011235

No comments:

Post a Comment