Question: For this exercise, you will write a function that takes a list of floats and returns a new list containing only the numbers from that

For this exercise, you will write a function that takes a list of floats and returns a new list containing only the numbers from that list that are within a designated interval. The file must be named interval.py and it must contain a single function named in_interval with four parameters:
The first is a list of floats.
The second is the lower bound of the interval.
The third is the upper bound of the interval.
The fourth is a Boolean indicating whether this is a closed interval. This parameter should have a default value of True indicating that the interval is closed.
The numbers in the returned list must be in the same order as they appeared in the original list. You may assume that the provided lower and upper values represent a valid interval.
Here are some examples illustrating the expected behavior:
>>> in_interval([20.1,0.0,2.5,1.4,-6.0],0.0,5.0) # Default is closed
[0.0,2.5,1.4]
>>> in_interval([20.1,0.0,2.5,1.4,-6.0],0.0,5.0, False)
[2.5,1.4]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!