Pybites Logo

Print names to columns

Level: Beginner (score: 2)

In this Bite you will use the modulo operation. You are presented with a function signature that receives a list of names and you have to print them to columns.

Each column should start with a pipe character (|) followed by a space, then the name should be wrapped in a field of 10 characters wide and it should left align.

The second cols argument determines to how many columns the names should be split. By default this is 2, but you bet our tests check other values too 😃

Here is a little demo how the code should work:

>>> names = 'Sara Tim Ana Julian'.split()
>>> from to_columns import print_names_to_columns
>>> print_names_to_columns(names)
| Sara      | Tim
| Ana       | Julian
>>> print_names_to_columns(names, cols=4)
| Sara      | Tim       | Ana       | Julian
>>>

Good luck and keep up the Python 🐍