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

126 out of 126 users completed this Bite.
Will you be the 127th person to crack this Bite?
Resolution time: ~33 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 3.67 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help