In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of December 7th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #08 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
Jon Snow, the Lord Commander of the Night's Watch, needs to present important information about the supplies and status of the Watch to his fellow brothers. To make it clear and organized, Jon wants to transform a list of strings into a formatted table with K columns, which he can easily display during their meetings at Castle Black.
John always wants the values to be right aligned on the table. The table should have K columns, each one of them with a width equal to the maximum length of a string in the input list. Each table cell should have a order with "+" n the corners, "|" by the sides and "-" on the bottom and upper parts. Any extra cells needed in the bottom row of the table should be left empty.
For instance, if K=4 and the list is ["Robb", "Sansa", "Arya", "Bran", "Rickon", "Jon"]), than the table should be (check the example function calls for more examples):
+------+------+------+------+ | Robb| Sansa| Arya| Bran| +------+------+------+------+ |Rickon| Jon| | | +------+------+------+------+
Write a function show_table(k, lst): that given an integer K and a list of strings lst, prints a neatly formatted table with K columns as described above.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |list| ≤ 100 | number of strings in the initial list | |
1 ≤ k ≤ 20 | number of columns in the table |
Example Function Calls | Example Output |
show_table(4, ["Robb", "Sansa", "Arya", "Bran", "Rickon", "Jon"]) show_table(2, ["Braavos","Dothraki","Lys","Pentos","Lhazar","Qarth","KingsLanding", "Dragonstone"]) show_table(3, ["Tyrion","Cersei","Jaime","Tiwin"]) |
+------+------+------+------+ | Robb| Sansa| Arya| Bran| +------+------+------+------+ |Rickon| Jon| | | +------+------+------+------+ +------------+------------+ | Braavos| Dothraki| +------------+------------+ | Lys| Pentos| +------------+------------+ | Lhazar| Qarth| +------------+------------+ |KingsLanding| Dragonstone| +------------+------------+ +------+------+------+ |Tyrion|Cersei| Jaime| +------+------+------+ | Tiwin| | | +------+------+------+ |