Python Programing Lab EXERCISE - 4(b)
Aim:
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even- valued terms.
The Fibonacci sequence is a series of numbers where a number is found by adding up the two numbers before it. Starting with 0 and 1, the series will be 0,1,1,2,3,5,8,13 and so forth.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the Recurrence relation:
With initial values F0 = 0 and F1 = 1
Program:
a=1
b=2
c=3
i=0
print(" The fibonacci series are :")
print(a,b)
while i <= 10:
c=a+b
print(c)
a=b
b=c
i=i+1
print("The sum of even valued term is :")
sum=0
i=0
while i <= 10:
if i%2 == 0:
print(i)
sum=sum+i
i=i+1
print("sum =",sum)
Output:
No comments