avatar Bite 314. Print names to columns

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 🐍


Login and get coding
go back Beginner level
Bitecoin 2X

22 out of 22 users completed this Bite.
Will you be Pythonista #23 to crack this Bite?
Resolution time: ~29 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 4.5 on a 1-10 difficulty scale.
» Up for a challenge? 💪

We use Python 3.8