Lesson goal: A list of numbers: Plot the histogram (Part 3)

Previous: A list of numbers: Make a histogram (Part 1) | Home | Next: A list of numbers: Plot the histogram (Part 3)

In the the last lesson we began work on constructing a histogram of the numbers in the data set. We put forth the idea of bins for the numbers, and computed the boundaries of each bin.

In this lesson, let's loop through all 2,000 data points and place each in its proper bin. What this actually means is for each data point, we'll see what bin it would fall into. And for each bin, we'll keep a tally/counter tracking how many times a number from the data set fell into a given bin.

This is handled in part 4 of the code below. Here, we have i looping through the data points one-by-one. And for each data[i], we'll examine each bin and see if the data point is between the low and high boundart of a bin. If so, we'll increase the count of that bin by one (as one more data point has fallen into that bin).

Now you try. Choose some number of bins and see how the counts in each bin comes out.

Type your code here:

See your results here: