"""
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.
"""
sumtotal=0
userInput = int(input("What is the max Fibonacci? "))

# Fibonacci number generator
def fib(max):
	fibs = []
	low = 0
	high = 1
	added = 0
	while (added <= max):
		fibs.append(added)
		added = low + high
		low = high
		high = added
	return fibs

# DEBUG: print list of fibonacci numbers from 0 to userInput
#print("Fibonacci Numbers:\n",fib(userInput))

# Iterate over fibonacci and sum even values
for i in fib(userInput):
	if (i % 2 == 0):
		sumtotal += i

print("Sum of even Fibonacci Numbers:\n", sumtotal)
# input of 4million returns "Total: 4613732"