<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wcswidth(pwcs, n=None):
 """ Given a unicode string, return its printable length on a terminal. Return the width, in cells, necessary to display the first ``n`` characters of the unicode string ``pwcs``. When ``n`` is None (default), return the length of the entire string. Returns ``-1`` if a non-printable character is encountered. """

    # pylint: disable=C0103
    #         Invalid argument name "n"

    end = len(pwcs) if n is None else n
    idx = slice(0, end)
    width = 0
    for char in pwcs[idx]:
        wcw = wcwidth(char)
        if wcw < 0:
            return -1
        else:
            width += wcw
    return width