Home > Problem, Projects/Experiments, Python > Python: Even Fibonacci Numbers

Python: Even Fibonacci Numbers

Python: Even Fibonacci Numbers
ProjectEuler Problem No.2

Easy fast task in ProjectEuler, The Task is to find the sum of the even-valued terms in Fibonacci sequence whose values do not exceed four million.

In this code we will add some print-statment to just show how mane even numbers there and the summation of it.

The Code:

# Even Fibonacci Numbers
# projectEuler Problem No. 2

def get_fibonacci_sequence():

n1 = 1

n2 = 1

fibo = 1

while fibo < 4000000:

fibo = n1+n2

n1 = n2

n2 = fibo

if fibo% 2 == 0:


tot = 0
even_fibo_num = []
print(‘\n We fond {} even fibonacci”s number less than 4000000.’.format(len(even_fibo_num)))
for each in even_fibo_num:

tot = tot + each

print(‘ The summation on those even Fibonacci”s is: ‘, tot)

Follow me on Twitter..

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s