<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def variable(self, var_name, shape, init, dt=tf.float32, train=None):
 """Adds a named variable to this bookkeeper or returns an existing one. Variables marked train are returned by the training_variables method. If the requested name already exists and it is compatible (same shape, dt and train) then it is returned. In case of an incompatible type, an exception is thrown. Args: var_name: The unique name of this variable. If a variable with the same name exists, then it is returned. shape: The shape of the variable. init: The init function to use or a Tensor to copy. dt: The datatype, defaults to float. This will automatically extract the base dtype. train: Whether or not the variable should be trained; defaults to True unless a default_scope has overridden it. Returns: A TensorFlow tensor. Raises: ValueError: if reuse is False (or unspecified and allow_reuse is False) and the variable already exists or if the specification of a reused variable does not match the original. """

    # Make sure it is a TF dtype and convert it into a base dtype.
    dt = tf.as_dtype(dt).base_dtype
    if var_name in self.vars:
      v = self.vars[var_name]
      if v.get_shape() != shape:
        raise ValueError(
            'Shape mismatch: %s vs %s. Perhaps a UnboundVariable had '
            'incompatible values within a graph.' % (v.get_shape(), shape))
      return v
    elif callable(init):
      if train is None:
        train = _defaults.get('trainable_variables', True)
      variable_collections = _defaults.get('variable_collections', ())
      if tf.GraphKeys.GLOBAL_VARIABLES not in variable_collections:
        variable_collections = list(variable_collections) + [
            tf.GraphKeys.GLOBAL_VARIABLES]

      v = tf.get_variable(var_name,
                          shape=shape,
                          dtype=dt,
                          initializer=init,
                          trainable=train,
                          collections=variable_collections)
      self.vars[var_name] = v
      return v
    else:
      v = tf.convert_to_tensor(init, name=var_name, dtype=dt)
      v.get_shape().assert_is_compatible_with(shape)
      self.vars[var_name] = v
      return v