Question: Please write in python and include explanations and screenshots to allow for viewing of correct indentations Define a function named case_table(a_dict, months_list) which takes a
Please write in python and include explanations and screenshots to allow for viewing of correct indentations
Define a function named case_table(a_dict, months_list) which takes a covid19 country-cases dictionary and a list of month names as parameters. - The function prints the contents of the dictionary in a table format as shown in the example below. The key of each dictionary item is the country name and the value is a list of monthly cases for the country. - The width of the first column is 15 and the the width of other columns is 10. The content of each column is aligned to the left edge of the column. - The second row of the table has a horizontal line of '-' characters. The function should also print the number of total cases at the end of each row. - Note: the function should print the table in ascending keys order.
| Test | Result |
data = {'Uruguay': [2634, 1049, 448], 'Taiwan': [120, 41, 26]} months_list = ['Nov', 'Oct', 'Sept'] case_table(data, months_list) | Name Nov Oct Sept Total ------------------------------------------------------- Taiwan 120 41 26 187 Uruguay 2634 1049 448 4131 |
data = {'NewZealand': [99, 121, 93, 177, 32], 'Singapore': [210, 261, 971, 4962, 8148], 'Thailand': [197, 216, 152, 102, 139]} months_list = ['Nov', 'Oct', 'Sept', 'Aug', 'Jul'] case_table(data, months_list) | Name Nov Oct Sept Aug Jul Total --------------------------------------------------------------------------- NewZealand 99 121 93 177 32 522 Singapore 210 261 971 4962 8148 14552 Thailand 197 216 152 102 139 806 |
data = {'Thailand': [197, 216, 152, 102, 139]} months_list = ['Nov', 'Oct', 'Sept', 'Aug', 'Jul'] case_table(data, months_list) | Name Nov Oct Sept Aug Jul Total --------------------------------------------------------------------------- Thailand 197 216 152 102 139 806 |
data = {'Uruguay': [2634, 1049, 448], 'Taiwan': [120, 41, 26]} months_list = ['Nov', 'Oct', 'Sept'] case_table(data, months_list) | Name Nov Oct Sept Total ------------------------------------------------------- Taiwan 120 41 26 187 Uruguay 2634 1049 448 4131 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
