Skip to content
Question

Q.Ms. Anjali, a data analyst, has been assigned the task of creating a histogram to display the age distribution of ten participants in a workshop. She has been provided with the following list of their ages : Ages = [22, 25, 24, 28, 30, 24, 29, 27, 21, 23] She has started writing a Python program for it. However, the code is incomplete. Help her complete the program by filling in the missing parts, so that the histogram as shown below is displayed. [Histogram figure titled "Age Distribution"; x-axis "Age" (20 to 30, bins of width 2), y-axis "Number of Participants" (0.0 to 3.0); legend labelled "Participants"; bar heights: 20-22 = 1, 22-24 = 2, 24-26 = 3, 26-28 = 1, 28-30 = 3] import matplotlib.pyplot as plt Ages = [22, 25, 24, 28, 30, 24, 29, 27, 21, 23] binsize=[20,22,24,26,28,30] plt.______(Ages, bins=binsize, edgecolor = 'black', label = 'Participants') # Statement-1 .xlabel('Age') # Statement-2 plt.ylabel('Number of Participants') plt.title("Age Distribution") plt. # Statement-3 _________ # Statement-4 I. Write the suitable code for the blank space in the line marked as Statement-1 which plots the histogram. II. Fill in the blank in Statement-2 to use the correct alias of the required module to set the label on x axis. III. Fill in the blank in Statement-3 with the correct Python code to display the legend on the graph. IV. Fill in the blank in Statement-4 with the appropriate Python code to display the graph.

CBSECBSE Class XII Board 2026Subjective· 4mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Ms. Anjali needs to complete four missing parts of a Python histogram program: the hist() function to plot, the plt alias for the x-axis label, legend() to display the legend, and show() to render the graph.

Data visualization transforms raw numbers into stories we can see at a glance. A histogram, one of the most fundamental tools in a data analyst's kit, groups continuous data into bins and shows how many observations fall into each range. Ms. Anjali's task is straightforward: take ten workshop participants' ages and reveal their distribution visually. The code skeleton is already in place—she's imported the matplotlib library (the workhorse of Python plotting), defined the ages list, and set up bin edges at two-year intervals from 20 to 30. What remains is filling in four critical blanks that bring the visualization to life.

Let's walk through each missing piece in the order they appear in the program.

Statement-1 is the heart of the entire operation. This line must actually create the histogram from the Ages data. The matplotlib.pyplot module (aliased as plt in the import statement) provides a dedicated function for this: hist(). The function takes the data as its first argument, then accepts parameters like bins (which define the grouping intervals), edgecolor (to outline each bar), and label (to identify the data series in the legend). So the complete line reads:

plt.hist(Ages, bins=binsize, edgecolor='black', label='Participants')

This single command does the heavy lifting—it counts how many ages fall into each bin (20–22, 22–24, and so on) and draws the corresponding bars.

Statement-2 labels the horizontal axis. The blank before .xlabel('Age') needs the alias that refers to the matplotlib.pyplot module. Since the import statement at the top reads import matplotlib.pyplot as plt, every function from that module is accessed through plt. The correct fill-in is simply:

plt.xlabel('Age')

This mirrors the structure of the very next line, plt.ylabel('Number of Participants'), which is already complete.

Note

The alias plt is a near-universal convention in Python data visualization. You'll see it in virtually every matplotlib example, making code instantly recognizable to other analysts.

Statement-3 must display the legend—that small box in the corner of the histogram that explains what "Participants" refers to. Matplotlib won't show a legend automatically just because you've provided a label parameter in the hist() call; you have to explicitly request it. The function for this is legend(), called on the plt object:

plt.legend()

Without this line, the label "Participants" would be defined but invisible.

Statement-4 is the final step: actually rendering the graph on screen. Up to this point, all the commands have been building a figure in memory—setting data, labels, title, legend. To make the histogram appear in a window (or in a Jupyter notebook output cell), you call:

plt.show()
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.