(s, min, max, default=None)
Parses the string and returns its value. If the value is outside the given
    range, its closest number within the range is returned

    >>> parse_range('5', 0, 10)
    5

    >>> parse_range('0', 5.0, 10)
    5.0

    >>> parse_range('15',0, 10)
    10

    >>> parse_range('x', 0., 20)
    10.0

    >>> parse_range('x', 0, 20, 20)
    20
Parses the string and returns its value. If the value is outside the given
    range, its closest number within the range is returned
Parses the string and returns its value . If the value is outside the given range its closest number within the range is returned
def parse_range(s, min, max, default=None):
    """
    Parses the string and returns its value. If the value is outside the given
    range, its closest number within the range is returned

    >>> parse_range('5', 0, 10)
    5

    >>> parse_range('0', 5.0, 10)
    5.0

    >>> parse_range('15',0, 10)
    10

    >>> parse_range('x', 0., 20)
    10.0

    >>> parse_range('x', 0, 20, 20)
    20
    """
    out_type = type(min)

    try:
        val = int(s)
        if val < min:
            return min
        if val > max:
            return max
        return val

    except (ValueError, TypeError):
        return default if default is not None else out_type((max - min) / 2)
def parse_range ( s , min , max , default = None ) : out_type = type ( min ) try : val = int ( s ) if val < min : return min if val > max : return max return val except ( ValueError , TypeError ) : return default if default is not None else out_type ( ( max - min ) / 2 )