# Even Fibonacci numbers
# Problem 2
#
# 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.

# first = 1
# second = 2
#
# print(first, second, sep="\n")
#
# for each in range(8):
#     temp = first + second
#     first = second
#     second = temp
#     print(each+3, second)


first = 1
second = 2
term_sum = 2

ran = 4000000

for each in range(ran-2):
    print("\rIteration {} from {} [{:.1%}]".format(each+1, ran-2, (each+1)/(ran-2)), end="")
    temp = first + second
    first = second
    second = temp
    if second % 2 == 0: term_sum += (each + 3)

print("\nSum: {}".format(term_sum))
