Python Program to Find the Sum of Fibonacci Series Numbers

In this article, we will show you how to write a Python program to find the sum of Fibonacci series numbers using a for loop, a while loop, and recursive functions. In this example, we used for loop to iterate from zero to n and find the sum of all the Fibonacci series numbers within that range.

Number = int(input("Please Enter the Fibonacci Number Range = "))

First = 0
Second = 1
Sum = 0

for Num in range(0, Number):
    print(First, end = '  ')
    Sum = Sum + First
    Next = First + Second
    First = Second
    Second = Next

print("\nThe Sum of Fibonacci Series Numbers = %d" %Sum)
Python Program to Find the Sum of Fibonacci Series Numbers

Program to Find the Sum of Fibonacci Series Numbers Using a while loop

This program finds the sum of Fibonacci Series numbers using a while loop. Please refer to For Loop and while Loop articles.

Number = int(input("Please Enter the Range = "))

First = 0
Second = 1
Sum = 0
i = 0

while(i <  Number):
    print(First, end = '  ')
    Sum = Sum + First
    Next = First + Second
    First = Second
    Second = Next
    i = i + 1

print("\nThe Sum = %d" %Sum)
Please Enter the Range = 24
0  1  1  2  3  5  8  13  21  34  55  89  144  233  377  610  987  1597  2584  4181  6765  10946  17711  28657  
The Sum = 75024

Python Program to Find the Sum of Fibonacci Series Numbers Using Recursion

This program finds the sum of all the Fibonacci Series numbers using recursion or recursive functions. 

def fibonacci(Number):
    if(Number == 0):
        return 0
    elif Number == 1:
        return 1
    else:
        return fibonacci(Number - 2) + fibonacci(Number - 1)
    

Number = int(input("Please Enter the Range = "))
Sum = 0

for Num in range(Number):
    print(fibonacci(Num), end = '  ')
    Sum = Sum + fibonacci(Num)


print("\nThe Sum = %d" %Sum)
Please Enter the Range = 30
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229
The Sum = 1346268