Skip to content

Commit

Permalink
Problem 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinzamaninasab authored Sep 11, 2020
1 parent 0656652 commit 9477b76
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Even Fibonacci numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sum_of_even_fibonacci = 0
a, b = 0, 1
while a < 4*10**6: # put an small number to sure the accuracy
a, b = b, b+a # each sequence, first and second number will be second number and sum of previous first and
# second number
# print(a) # make sure that work's fine!
if a % 2 == 0:
# print(a) # make sure we find the right number
sum_of_even_fibonacci += a
# print(sum_of_even_fibonacci) # make sure again
print(sum_of_even_fibonacci)

1 comment on commit 9477b76

@hosseinzamaninasab
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Please sign in to comment.