In the previous exercise, you found that the earliest transaction time is close to 0, and the latest transaction is close to 24, making your range nearly 24 hours.

Now, we have the information we need to start building our histogram. The two key features of a histogram are bins and counts.


A bin is a sub-range of values that falls within the range of a dataset. In the grocery store example, a valid bin may be from 0 hours to 6 hours. This bin includes all times from just after midnight (0) until 6 am (6).

Additionally, all bins in a histogram must be the same width.

If the range of values in our dataset is from 0 to 24, and the first bin in our grocery store example is from 0 to 6, can you figure out the minimums and maximums of the other bins?

The grocery store bins are:

  • 0 to 6 hours
  • 6 to 12 hours
  • 12 to 18 hours
  • 18 to 24 hours



In script.py, there is an array called days_old_bread that contains values for the age of different loaves of bread in the grocery store.

Find the minimum value of the array and save it to min_days_old.


Find the maximum value of the array and save it to max_days_old.


Set the variable bins equal to 3.

When you run the code, it will output the number of bins for this histogram, and the width of these bins. In the next exercise, we’ll figure out which values fall into each bin.

At the bottom of script.py, we calculate the bin width by subtracting min_days_old from max_days_old, adding one, then dividing by three. We must add one because there are nine possible answers from zero to eight.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?