Closed harshraj8843 closed 2 years ago
Takes the user input Initial Values for Fibonacci Series are 0 and 1 Use for loop till n-2 Add the n1 and n2 Swap the values Print sum
n = int(input())
n1 = 0
n2 = 1
print(n1,n2,end=" ")
for i in range(0,n-2):
sum = n1+n2
n1 = n2
n2 = sum
print(sum, end=" ")
This is the more optimized one
n = int(input()) n1, n2 = 0, 1 for i in range(0,n): print(n1, end=" ") n1, n2 = n2, n1+n2
Hii @PA11TEDDU
Thanks for contributing to this open source project 😃
Could you open a pull request for this
Title of article
Write a Python program to print Fibonacci series.
Additional information
Code of Conduct