Question: Previously, an x was used to represent every integer value. However, we don't have space to represent large values using the approach (e.g., it would

Previously, an x was used to represent every integer value. However, we don't have space to represent large values using the approach (e.g., it would be unreadable if the values were in the hundreds or thousands). Therefore. we need to scale the bars so that each X represents a larger quantity.

We will display the bars as percentages, where the largest value in the data set is treated as 100%- The height of the other bars will be proportional to the largest value in the set. This allows us to set the size of the histogram and ensure that the data is displayed in a format that is easy to read and understand.

Write a function called generate_histogram_03 that accepts 2 arguments. The first argument should be a dictionary containing the table of data that we want to display in the histogram. The second argument is an integer representing the maximum length of a bar (number of Xs) vw'thin the table. This argument will be used to determine the scale that we will apply when drawing the bars. Use a Keyword argument max_bar_length with a default value ol 10 to set the default size of the bar.

For example, it you had a table of data as follows:

A: 2

B: 1

C: 5

and you scaled the histogram to display with the default size (where the longest bar Is 10 character long). then you would need to double the size 01 each value when displaying it (e.g. A" 4, B: 2, C: 10) so that the longest bar length is 10.

It you had values of A3, 8:5, C: 2, and you displayed with a maximum bar length of 20, then you would need to multiple each length by 4, giving A12, 8120, 0:8.

After scaling the length of each bar. you should round to the nearest integer value when you print out the number of X5. You may choose to make use of the function you defined in the previous exercise to get the largest value in a dictionary. Remember to submit all the functions you need to make your code work correctly.

For example:

Test data = {'a': 1, 'b': 5, 'c': 3} generate histogram_03 (data,

Test data = {'a': 1, 'b': 5, 'c': 3} generate histogram_03 (data, 5) data = {'a': 1, 'b' : 5, 'c': 3} generate histogram_03(data, 10) data = {'a': 1, 'b' : 5, 'c': 3} generate histogram_03 (data) data = {'a': 10, 'b': 50, 'c': 30} generate histogram_03(data) Result a x b XXXXX c XXX a XX b xxxxxxxxxxxxxxxxxXX c XXXXXX a XX b xxxxxxxxxx c XXXXXX a XxX b xXxxxxxxxxx c XXXXXX

Step by Step Solution

3.45 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To create the generatehistogram03 function you need to scale the values in the dictionary relative t... View full answer

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!