def positive_int ( val ) : if isinstance ( val , float ) : raise ValueError ( '"{}" must not be a float' . format ( val ) ) val = int ( val ) if val >= 0 : return val raise ValueError ( '"{}" must be positive' . format ( val ) )
how to cast a float as an int in python
Parse val into a positive integer .
def positive_int(val):
    """Parse `val` into a positive integer."""
    if isinstance(val, float):
        raise ValueError('"{}" must not be a float'.format(val))
    val = int(val)
    if val >= 0:
        return val
    raise ValueError('"{}" must be positive'.format(val))