Question: Write a function make_table that returns a string with an HTML code for a table. The function has a single argument, a list of lists;
Write a function make_table that returns a string with an HTML code for a table. The function has a single argument, a list of lists; such as [["Col1","Col2","Col3"],[11,12,13],[21,22,23],[31,32,33]] (that stores a header and integer values). Here's an visual output of the example table:
Your function should include an appropriate docstring, comments, and good variable names for readability.
The rules for the function are as follows:
- Each nested list corresponds to a table row.
- The first row sets the header columns of the table.
- The number of columns should always be the same.
- If a row contains different number of columns than the first one, the function return "The number of columns should be the same!" message.
- If the list is empty, the function returns None.
- Otherwise, your function should return the HTML code as a string that creates a corresponding table.
- The Type 1 borders of the table should be enabled.
Your function only needs to return the HTML code as a string:
- "
- number 1
- "
...
" (table structure example)
Some example calls to the function:
- make_table([["Col1","Col2","Col3"],[11,12,13],[21,22,23]]) should return the HTML table structure for a table with a header row, 2 data rows, and 3 columns for each row.
- make_table([["Col1","Col2","Col3"],[11,12,13],[21,22,23],[31,32,33,34]]) should return "The number of columns should be the same!"
python
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
