-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0656652
commit 9477b76
Showing
1 changed file
with
11 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
9477b76
There was a problem hiding this comment.
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.