def keep_within_range(minimum, maximum, x):
    """
    Returns the value of x limited to the range [min, max]
    This means if x is less than min, min is returned.
    If x is greater than max, max is returned.
    """
    if x <= minimum:
        return minimum
    elif x >= maximum:
        return maximum
    else:
        return x