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
- Create a function fibo.
- Use the def keyword to define the function.
- Create two variables num1, and num2, and assign their values equal to 0 and 1.
- Create a count variable and assign its values equal to 0.
- While the count variable is less than 10 print num1.
- Add num1 and num2 and store the result in a new variable n2.
- Change num1 to num2 and num2 to n2 and add 1 to the count variable.
- 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
Python function program to get unique values from the given list.
Python function program to get the duplicate characters from the string.
Python function program to get the square of all values in the given dictionary.
Python function program to create dictionary output from the given string.
Python function program to print a list of prime numbers from 1 to 100.