Program to get the Fibonacci series up to the given number

In this python function program, we will create a function to get the Fibonacci series up to the given number.

What is the Fibonacci series?
The Fibonacci sequence is a set of integers (the Fibonacci numbers) that starts with a zero, followed by a one, then by another one, and then by a series of steadily increasing numbers.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function fibo.
  2. Use the def keyword to define the function.
  3. Create two variables num1, and num2, and assign their values equal to 0 and 1.
  4. Create a count variable and assign its values equal to 0.
  5. While the count variable is less than 10 print num1.
  6. Add num1 and num2 and store the result in a new variable n2.
  7. Change num1 to num2 and num2 to n2 and add 1 to the count variable.
  8. Call the function to get the output.
				
					def fibo():
    num1 = 0
    num2 = 1
    count = 0

    while count < 10:
        print(num1,end=" ")
        n2 = num1 + num2
        num1 = num2
        num2 = n2
        count += 1
fibo()
				
			

Output :

				
					0 1 1 2 3 5 8 13 21 34 
				
			

Related Articles

get the factorial of a given number.

check whether a combination of two numbers has a sum of 10 from the given list.

Leave a Comment