Question: The programming languager is Python. Neither Minimum nor Maximum Given a list of numbers ( the list may not be sorted and may also contain

The programming languager is Python. Neither Minimum nor Maximum
Given a list of numbers (the list may not be sorted and may also contain duplicates), find an element which is neither the maximum of the list, nor the
minimum. You may assume that one such element exists, in other words, your code will be tested with only such lists.
For example, if 2,2,2,2,1,0,5,3,2,1,-1,3,2,1,2 is the input list, then 1 is one possible answer.
Possible solution which will take more time: Compute the max and the min (possibly using the built-in functions max and min), and then run through the list
with a loop. Whenever you find an element which is different from both max and min, return that. If you implement this algorithm, you will get only 60% credit
for this assignment.
In [2]: # Input: a list, Returns an element of the list
def neitherMaxNorMin(L):Several lines of code here
return None # Change this line appropriately
In [3]: # Visible Tests
L}=[2,2,2,2,1,0,5,3,2,1,-1,3,2,1,2
answer = neitherMaxNorMin(L)This need not be efficient, needs to be correct in the simplest wayassert(answer in L), "The element must be in the list."
assert(answer !=max(L)), "The element should not be the maximum."
assert(answer !=min(L)), "The element should not be the minimum."
AssertionError Traceback (most recent call last)
Given a list of numbers (the list may not be sorted and may also contain duplicates), find an element which is neither the maximum of the list, nor the minimum. You may assume that such a number exists in the list. Besides writing correct code, you should also write:
Neither Minimum nor Maximum
Given a list of numbers (the list may not be sorted and may also contain duplicates), find an element which is neither the maximum of the list, nor the minimum. You may assume that one such element exists, in other words, your code will be tested with only such lists.
For example, if [2,2,2,2,1,0,5,3,2,1,-1,3,2,1,2] is the input list, then 1 is one possible answer.
Possible solution which will take more time: Compute the max and the min (possibly using the built-in functions max and min), and then run through the list with a loop. Whenever you find an element which is different from both max and min, return that. If you implement this algorithm, you will get only 60% credit for this assignment.
The programming languager is Python. Neither

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 Programming Questions!