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 is the input list, then is one possible answer.
Possible solution which will take more time: Compute the max and the min possibly using the builtin 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 credit
for this assignment.
In : # Input: a list, Returns an element of the list
def neitherMaxNorMinL:Several lines of code here
return None # Change this line appropriately
In : # Visible Tests
L
answer neitherMaxNorMinLThis need not be efficient, needs to be correct in the simplest wayassertanswer in L "The element must be in the list."
assertanswer maxL "The element should not be the maximum."
assertanswer minL "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 is the input list, then is one possible answer.
Possible solution which will take more time: Compute the max and the min possibly using the builtin 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 credit for this assignment.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
