Python Programing Lab EXERCISE - 4(b)

Python Programing Lab EXERCISE - 4(b)

Aim:
page23image5798992
              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.

Description:

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 Fof Fibonacci numbers is defined by the Recurrence relation:

                      F= Fn-1 + Fn-2

With initial values F= 0 and F= 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

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...