Write a python program that uses function to find the sum of the even-valued terms in the Fibonacci sequence whose values do not exceed ten thousand.

 def evenfib(n):

    evensum,prev,next1=0,0,1

    fib=[0]

    while(next1<=n):

        fib.append(next1)

        if next1 % 2==0:

            evensum = evensum+next1

        prev,next1=next1,prev+next1

    print("The sum of even valued fib sequence",fib,"is",evensum)

n=10000

evenfib(n)


Comments

Popular posts from this blog

Write a python program to compute cumulative product of a list of numbers (write function cumulative_product).

Write a Python program to compute distance between two points taking input from the user. Formula for Pythagorean theorem for compute distance between two points is: