Question: Define a function named print_table(name, column_names, a_dict) which takes a table name, a list of column names and a dictionary of data as parameters and

Define a function named print_table(name, column_names, a_dict) which takes a table name, a list of column names and a dictionary of data as parameters and prints the table as shown in the examples below. For example, if the table name is 'Regions', the column names list is ['Auckland region', 'Northland region'] and the dictionary is:

{'Northland region': [(2021, 2262), (2022, 2367)], 'Auckland region': [(2021, 20520), (2022, 20469)]}

then the function prints the table below:

produces:

Regions |2021 |2022 | -------------------------------- Auckland region |20520 |20469 | Northland region |2262 |2367 |

Note:

You can assume that all parameters are valid.

The width of the first column (i.e. label) in the table is obtained by calling the get_longest_string_length() function that you wrote in Q6. You can assume that the function is given.

The width of the remaining columns in the table is obtained by calling the get_longest_column_length() function that you wrote in Q7. You can assume that the function is given.

You may find the f-string helpful. For example: use "{name:<{width}}" to print the name with a specific width value.student submitted image, transcription available below

Define a function named print_table(name, column_names, a_dict) which takes a table name, a list of column names and a dictionary of data as parameters and prints the table as in the examples below. For example, if the table name is 'Regions', the column names list is ['Auckland region', 'Northland region' ] and the dictionary is: \{'Northland region': [(2021,2262), (2022, 2367)], 'Auckland region': [(2021,20520),(202 then the function prints the table below: produces: Note: - You can assume that all parameters are valid. - The width of the first column (i.e. label) in the table is obtained by calling the get_longest_string_length () function that you wrote in Q6. You can assume that the function is given. - The width of the remaining columns in the table is obtained by calling the get_longest_column_length () function that you wrote in Q7. You can assume that the function is given. - You may find the f-string helpful. For example: use " { name : { width }}" to print the name with a specific width value. For example: Test years =[2021,2022] a_dict ={ 'Northland region': [(2021,2262),(2022,2367)], 'Auckland region': [(2021,20 print_table("Regions", years, a_dict)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!