Question: Define a function named in_range(v, min_mag, max_mag) that takes three numbers as input. The parameters min_mag and max_mag are non-negative values that represent magnitude limits

Define a function named in_range(v, min_mag, max_mag) that takes three numbers as input. The parameters min_mag and max_mag are non-negative values that represent magnitude limits for v. If the magnitude of v is between min_mag and max_mag, then v is returned, otherwise the magnitude of v is reduced to be in the range min_mag to max_mag and this value is returned. Example:

in_range(3, 2, 5) returns 3

in_range(-3, 2, 5) returns -3

in_range(1, 2, 5) returns 2

in_range(7, 2, 5) returns 5

in_range(-1, 2, 5) returns -2

in_range(-7, 2, 5) returns -5

The case of 0 is ambiguous. In this case, return min_mag

using python

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!