old_contents: """
  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.
  """
  
  MAX = 4000000
  
  if __name__ == "__main__":
      prev = 0
      curr = 2
  
      total = 0
  
      while curr < MAX:
          total += curr
  
          # even numbers in fibonacci sequence can be calculated by:
          # next = (next * 4) + previous
          prev, curr = curr, curr * 4 + prev
  
      print(total)
  
new_contents: """
  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.
  """
  
  MAX = 4000000
  
  def even_fibonacci():
      previous = 0
      current = 2
  
      yield prev
      yield curr
  
      while True:
          previous, current = current, current * 4 + previous
          yield current
  
  if __name__ == "__main__":
      total = 0
  
      for fib in even_fibonacci():
          if fib >= MAX:
              break
  
          total += fib
  
      print(total)
  
subject: change python solution for problem 2 using generator function