Python Program to Print Fibonacci Sequence 2

Aim:

By considering the terms in the Fibonacci sequence whose values do not exceed four
million, find the sum of the even-valued terms.

Program:

a, b = 1, 2
total = 0
print(a,end=" ")
while (a <=4000000-1):
if a % 2 == 0:
total += a
a, b = b, a+b
print(a,end=" ")
print("\n sum of prime numbers term in fibonacci series: ",total)

Output:

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 832040 1346269 2178309 3524578 5702887

sum of prime numbers term in Fibonacci series: 4613732 

Leave a Comment