Background
I am stuck in this problem:
Each new member of the Fibonacci sequence is generated by adding the two previous members. Starting from 1 and 2, the first 10 members will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Considering the members in the Fibonacci sequence, whose values do not exceed four million, we find the sum of the even members.
I tried to find out if the problem was my Fibonacci number generator, code that gets even numbers, or even the way I add numbers to no avail.
the code
I decided to keep the numbers on the lists. Here I create them.
list_of_numbers = []
even_fibs = []
Then I created a generator. This is a potential area of concern .
x,y = 0,1
while x+y <= 4000000:
list_of_numbers.append(y)
x, y = y, x+y
Then I created code to check the parity of the number, and then add it to the list even_fibs. This is another weak point in the code.
coord = 0
for number in range(len(list_of_numbers)):
test_number = list_of_numbers [coord]
if (test_number % 2) == 0:
even_fibs.append(test_number)
coord+=1
, .
print "Normal: ", list_of_numbers
print "\nEven Numbers: ", even_fibs
print "\nSum of Even Numbers: ", sum(even_fibs)
, , ? , - .