<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def truncate(string, maxlen, end=True):
 """Truncate a string. Parameters string : `str` String to truncate. maxlen : `int` Maximum string length. end : `boolean`, optional Remove characters from the end (default: `True`). Raises ------ ValueError If `maxlen` <= 3. Returns ------- `str` Truncated string. Examples -------- 'str' """

    if maxlen <= 3:
        raise ValueError('maxlen <= 3')

    if len(string) <= maxlen:
        return string

    if end:
        return string[:maxlen - 3] + '...'

    return '...' + string[3 - maxlen:]