input: def MatrixOperations(matrix: Matrix, operation: str, other_matrix: Matrix = None) -> Matrix:
      """ Perform various matrix operations such as addition, subtraction, multiplication, and transpose.
      The operations are performed based on the operation type provided. If the operation is 'add' or 'sub', 
      the other_matrix must be provided. If the operation is 'mul', the other_matrix must also be provided,
      and if the operation is 'transpose', no other_matrix is required.
      
      Example:
      >>> mat1 = Matrix(2, 2, [1, 2, 3, 4])
      >>> mat2 = Matrix(2, 2, [5, 6, 7, 8])
      >>> result = MatrixOperations(mat1, 'add', mat2)
      >>> print(result)
      6 8 
      10 12
      
      """
output:     if operation == 'add':
          if other_matrix is None:
              raise ValueError("Other matrix must be provided for addition.")
          if matrix.rows != other_matrix.rows or matrix.cols != other_matrix.cols:
              raise ValueError("Matrices must have the same dimensions for addition.")
          result = Matrix(matrix.rows, matrix.cols)
          for i in range(matrix.rows):
              for j in range(matrix.cols):
                  result[i][j] = matrix[i][j] + other_matrix[i][j]
          return result
      
      elif operation == 'sub':
          if other_matrix is None:
              raise ValueError("Other matrix must be provided for subtraction.")
          if matrix.rows != other_matrix.rows or matrix.cols != other_matrix.cols:
              raise ValueError("Matrices must have the same dimensions for subtraction.")
          result = Matrix(matrix.rows, matrix.cols)
          for i in range(matrix.rows):
              for j in range(matrix.cols):
                  result[i][j] = matrix[i][j] - other_matrix[i][j]
          return result
      
      elif operation == 'mul':
          if other_matrix is None:
              raise ValueError("Other matrix must be provided for multiplication.")
          if matrix.cols != other_matrix.rows:
              raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix for multiplication.")
          result = Matrix(matrix.rows, other_matrix.cols)
          for i in range(matrix.rows):
              for j in range(other_matrix.cols):
                  result[i][j] = sum(matrix[i][k] * other_matrix[k][j] for k in range(matrix.cols))
          return result
      
      elif operation == 'transpose':
          result = Matrix(matrix.cols, matrix.rows)
          for i in range(matrix.rows):
              for j in range(matrix.cols):
                  result[j][i] = matrix[i][j]
          return result
      
      else:
          raise ValueError("Invalid operation type.")