A delivery app tracks how long a courier takes to reach a restaurant: a continuous time , in minutes, that always lands somewhere between and . The data team has worked out the shape of its density curve, a function shape(x) that is never negative, but they never scaled it. The area under it is generally not 1.
The average of a continuous quantity is an integral: every possible value, weighted by its density, added up.
Here has to be a genuine density curve: never negative, and enclosing a total area of exactly 1.
Task: write density_mean(shape, a, b, n) that estimates the average of with rectangles and returns it rounded to 4 decimal places.
shape is a Python function that takes one number and returns one number: shape(2.5) is the height of the curve at .n rectangles of equal width.n slices for every area you estimate.For example, for the shape on with 4 rectangles, the answer is 1.5568.