Print first N Fibonacci Numbers in python

Print first N Fibonacci Numbers using Python Programming Language.

 

Answer )

Below code is for print first N Fibonacci Numbers for up to that range(N).

Input : n = 4
Output : 0 1 1 2

Input : n = 8
Output : 0 1 1 2 3 5 8 13
Input : n = 0
Output : Fibonacci Series is not possible

Input : n = -2
Output : Fibonacci Series is not possible
 

Below code is only on Python language.

If it is helpful for you , then comment below .

 

Code:

def fibonacciSeries(n):
f1 = 0
f2 = 1
if (n < 1):
print("Fibonacci Series is not possible",end=" ")
return
print(f1, end=" ")
for x in range(1, n):
print(f2, end=" ")
f3 = f1 + f2
f1 = f2
f2 = f3

n = int(input("Enter Number : "))
fibonacciSeries(n)

 

 

Code Picture View:


 Output Picture View:

 

 

 

 

 

If you want Some basic Programs : 

Prime Numbers up to N in python , Click Here 

Prime Numbers up to N in java, Click Here

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Comments

Post a Comment

Popular posts from this blog

Print prime numbers up to N and Check N is prime or not using Java Programming Language

javascript arrow function