def pad(s, n):
    """Pad a string with spaces on both sides until long enough"""
    while len(s) < n:
        if len(s) < n:
            s = s + " "
        if len(s) < n:
            s = " " + s
    return s