Python Program to find fibonacci series

Program

num = int(input("Enter the range of fibonacci series:\t"))
first = 0
second = 1
i = 0
print("Fibonacci Series")
while(i < num):
    if(i <= 1):
        next = i
    else:
        next = first + second
        first = second
        second = next
    print(next,"\t",end="")
    i = i + 1
print()

This program generates the Fibonacci series up to a specified range entered by the user.

  1. User Input for Range

    • The user specifies how many terms of the Fibonacci series should be printed.
  2. Initialize Variables

    • first = 0 and second = 1 store the first two numbers of the series.
  3. Loop to Generate Fibonacci Series

    • If i <= 1, the next term is i (handling the first two values separately).
    • For other terms, the next number is calculated as first + second.
    • The variables first and second are updated accordingly.
  4. Printing the Series

    • The print() function prints each term in a single line with a tab space.

Key Takeaways

  • Uses a while loop to generate Fibonacci numbers up to the given range.
  • The first two numbers are handled separately.
  • Updates variables dynamically to compute new terms efficiently.

Output

Enter the range of fibonacci series:	6
Fibonacci Series
0 	1 	1 	2 	3 	5