Sum of fibonacci series in Python
In this post, you will learn how to find the sum of fibonacci series using the Python programming language.
The Fibonacci series is the sequence of numbers in which the next number is the sum of the previous two numbers. The Fibonacci series was known hundreds of years earlier. The "Fibonacci" name came from the nickname "Bonacci".
We can easily remember the Fibonacci Sequence using November 23rd as the Fibonacci Day. As November 23rd has the digits "1, 1, 2, 3", which is part of the sequence.
In the above image, the first two numbers are 0 and 1. So, according to the Fibonacci rule, the third number is 1 (sum of 0 and 1). The fourth number is 2, and so on.
0 + 1 = 1 // 0, 1, 1
1 + 1 = 2 // 0, 1, 1, 2
1 + 2 = 3 // 0, 1, 1, 2, 3
2 + 3 = 5 // 0, 1, 1, 2, 3, 5
0 ,1 , 1, 2, 3, 5, 8, 13, 21, 34....
Python program to find the sum of Fibonacci Series numbers using for loop
In this Python program, we have used the for loop to iterate from zero to n and find the sum of all the Fibonacci Series numbers within that range.
Number = int(input("Enter the fibonacci number range: "))
n1 = 0
n2 = 1
Sum = 0
for Num in range(0, Number):
print(n1, end = ' ')
Sum = Sum + n1
Next = n1 + n2
n1 = n2
n2 = Next
print("\nSum of Fibonacci Series Numbers: %d" %Sum)
Output of the above code:
Enter the fibonacci number range: 10
0 1 1 2 3 5 8 13 21 34
Sum of Fibonacci Series Numbers: 88
Python program to find the sum of Fibonacci Series numbers using while loop
In this Python program, we have used the while loop to find the sum of all the Fibonacci Series numbers within that range.
num = int(input("Enter the Fibonacci Number Range: "))
n1 = 0
n2 = 1
Sum = 0
i = 0
while(i < num):
print(n1, end = ' ')
Sum = Sum + n1
Next = n1 + n2
n1 = n2
n2 = Next
i = i + 1
print("\nSum of Fibonacci Series Numbers: %d" %Sum)
Output of the above code:
Enter the Fibonacci Number Range: 12
0 1 1 2 3 5 8 13 21 34 55 89
Sum of Fibonacci Series Numbers: 232
Related Articles
Count consonants in a string Python
Python split strings by comma
Count vowels in a string Python
Replace multiple characters Python
Convert array to list Python
Python loop through list
Difference between tuple and list in Python
Convert string to list Python
Remove last element from list Python
Convert list to string Python
Convert Python list to numpy array
Remove element from list Python
Python dict inside list
Check if list is empty Python
Python iterate list with index
Python iterate list with index
Python split string by comma
Printing Simple Diamond Pattern in Python
Stemming and Lemmatization in Python
Python | Generate QR Code using pyqrcode module