Where the Bars Begin

Data with PythonEasy+10 XP+10

Where the Bars Begin

Before drawing a histogram, it helps to know where each bar will start and stop. ax.hist splits the range from the smallest value to the largest value into bins bins of equal width. The points where one bin ends and the next begins are the bin edges.

Task: write bin_edges(values, bins).

  • Return every edge, from the smallest value up to the largest value, as a list of floats rounded to 2 decimal places.
  • With bins bins there are bins + 1 edges: the first is the smallest value and the last is the largest.
  • values always holds at least two different numbers, in any order, and bins is at least 1.

Examples

values = [2700, 6300, 3400, 4100]
bins = 10
returns [2700.0, 3060.0, 3420.0, 3780.0, 4140.0, 4500.0, 4860.0, 5220.0, 5580.0, 5940.0, 6300.0]
values = [5, 1, 3, 2, 4]
bins = 4
returns [1.0, 2.0, 3.0, 4.0, 5.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run