# 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.


# Defines Fibonacci sequence up to last term <= n
def fibonacci(n):
    fib_sequence = [1, 2]
    while fib_sequence[len(fib_sequence) - 1] <= n:
        fib_sequence.append(fib_sequence[len(fib_sequence) - 1] + fib_sequence[len(fib_sequence) - 2])

    fib_sequence.pop(len(fib_sequence) - 1)  # Removes last element
    return fib_sequence


# Removes the odd elements from a list
def get_evens(elements):
    i = 0
    while i < len(elements):
        if elements[i] % 2 == 1:
            elements.pop(i)
            i -= 1
        i += 1


if __name__ == '__main__':
    sequence = fibonacci(4000000)
    get_evens(sequence)
    print(sum(sequence))

4e58c444c8ac53dd955af8ba040b212fe2a2bc0a
<mask token>

<mask token>


def get_evens(elements):
    i = 0
    while i < len(elements):
        if elements[i] % 2 == 1:
            elements.pop(i)
            i -= 1
        i += 1


<mask token>

def fibonacci(n):
    fib_sequence = [1, 2]
    while fib_sequence[len(fib_sequence) - 1] <= n:
        fib_sequence.append(fib_sequence[len(fib_sequence) - 1] +
            fib_sequence[len(fib_sequence) - 2])
    fib_sequence.pop(len(fib_sequence) - 1)
    return fib_sequence


def get_evens(elements):
    i = 0
    while i < len(elements):
        if elements[i] % 2 == 1:
            elements.pop(i)
            i -= 1
        i += 1


<mask token>

def fibonacci(n):
    fib_sequence = [1, 2]
    while fib_sequence[len(fib_sequence) - 1] <= n:
        fib_sequence.append(fib_sequence[len(fib_sequence) - 1] +
            fib_sequence[len(fib_sequence) - 2])
    fib_sequence.pop(len(fib_sequence) - 1)
    return fib_sequence


def get_evens(elements):
    i = 0
    while i < len(elements):
        if elements[i] % 2 == 1:
            elements.pop(i)
            i -= 1
        i += 1


if __name__ == '__main__':
    sequence = fibonacci(4000000)
    get_evens(sequence)
    print(sum(sequence))

# 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.


# Defines Fibonacci sequence up to last term <= n
def fibonacci(n):
    fib_sequence = [1, 2]
    while fib_sequence[len(fib_sequence) - 1] <= n:
        fib_sequence.append(fib_sequence[len(fib_sequence) - 1] + fib_sequence[len(fib_sequence) - 2])

    fib_sequence.pop(len(fib_sequence) - 1)  # Removes last element
    return fib_sequence


# Removes the odd elements from a list
def get_evens(elements):
    i = 0
    while i < len(elements):
        if elements[i] % 2 == 1:
            elements.pop(i)
            i -= 1
        i += 1


if __name__ == '__main__':
    sequence = fibonacci(4000000)
    get_evens(sequence)
    print(sum(sequence))
