def clip(value, min, max):
    """Clips (limits) the value to the given limits.

    The output is at least `min`, at most `max` and `value` if that value
    is between the `min` and `max`.

    Args:
        value: to be limited to [min, max]
        min: smallest acceptable value
        max: greatest acceptable value

    Returns:
        the given value if within [min, max] or min if value is smaller than
        min or max if value is greater than max.
    """
    if value < min:
        return min
    elif value > max:
        return max
    else:
        return value