def p2(max):
    """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.
    """

    fib_num = [1,2]
    sum_even = 0
    while fib_num[-1] < max:
        # check if next fibonacci number is even
        if (fib_num[-1] % 2) == 0:
            sum_even = sum_even + fib_num[-1]

        next_num = fib_num[-2]+fib_num[-1]

        fib_num.append(next_num)

    print("Sum of even Fibonacci numbers less than %f is %g" % (max, sum_even))

    return sum_even