code: def exec_then_eval(code, namespace=None):
      
      # TODO: make this less brittle.
      namespace = namespace or {}
  
      block = ast.parse(code, mode='exec')
      last = ast.Expression(block.body.pop().value)
  
      exec(compile(block, '<string>', mode='exec'), namespace)
      return eval(compile(last, '<string>', mode='eval'), namespace)
docs: Exec a code block & return evaluation of the last line