Question: In a file named histogram.py , implement the function histogram. The function will take two input parameters: ( 1 ) a list of dictionaries, and

In a file named histogram.py, implement the function histogram. The function will take two input parameters: (1) a list of dictionaries, and (2) a string. The string will indicate what attribute will be plotted. You can also assume that the string provided is a key in all dictionaries in the list of dictionaries. The function will go through all students and store the number of students that are at each level of the attribute. For example, if the attribute is School, it will store the number of students for each school. For numerical values (e.g., Age), you need to define 10 intervals between 0 and the maximum value of the attribute. Note that you do not know in advance which values will be there. This data will then be used to plot a histogram. The function will plot and show the histogram. The function will return -1 if the attribute is categorical (School) and the maximum value for the given attribute if it is numerical.
Note: You have both numerical and string attributes. As hist only works with numerical values, you cannot use this function. You are required to use the function bar from Matplotlib.pyplot. You are not allowed to use hist.
Tests:
1) test_show (test_histogram.histogram_test_case)
2) test_xlabel (test_histogram.histogram_test_case)
3) test_ylabel (test_histogram.histogram_test_case)
4) test_title (test_histogram.histogram_test_case)
5) test_bar (test_histogram.histogram_test_case)
6) test_figure (test_histogram.histogram_test_case)
7) test_return (test_histogram.histogram_test_case)

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 Programming Questions!