Python-Fibonacci-Sum

Python

Fibonacci Series Sum

#!/bin/python3
import math
import os
import random
import re
import sys
def sumOfFibonacciNumbers(n):
sum=0;
if n<2:
return 0
else:
#print("n is" +str(n))
fibonacciSeries=[0,1]
for i in range(2,n):
nextElement=fibonacciSeries[i-1]+fibonacciSeries[i-2]
fibonacciSeries.append(nextElement)
for i in range(1,len(fibonacciSeries)):
sum=sum+fibonacciSeries[i]
return sum
if _name_=='_main_':
fptr=open(os.environ['OUTPUT_PATH'],'w')
n=int(input().strip())
result=sumOfFibonacciNumbers(n)
fptr.write(str(result)+'\n')
fptr.close()

 

Leave a Comment

Your email address will not be published. Required fields are marked *