Python Programming

Python-Fibonacci-Sum

Python Fibonacci Series Sum #!/bin/python3import mathimport osimport randomimport reimport sys def sumOfFibonacciNumbers(n):sum=0;if n<2:return 0else:#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 sumif _name_==’_main_’:fptr=open(os.environ[‘OUTPUT_PATH’],’w’)n=int(input().strip())result=sumOfFibonacciNumbers(n)fptr.write(str(result)+’n’)fptr.close()