<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fmt_repertoire(r):
 """Format a repertoire."""

    # TODO: will this get unwieldy with large repertoires?
    if r is None:
        return ''

    r = r.squeeze()

    lines = []

    # Header: 'S      P(S)'
    space = ' ' * 4
    head = '{S:^{s_width}}{space}Pr({S})'.format(
        S='S', s_width=r.ndim, space=space)
    lines.append(head)

    # Lines: '001     .25'
    for state in utils.all_states(r.ndim):
        state_str = ''.join(str(i) for i in state)
        lines.append('{0}{1}{2}'.format(state_str, space,
                                        fmt_number(r[state])))

    width = max(len(line) for line in lines)
    lines.insert(1, DOTTED_HEADER * (width + 1))

    return box('\n'.join(lines))