Question: My Nondestructive Function can be Used if needed Test Cases: Python3 No str() please try to do it in a simplistic way (: Add comments

My Nondestructive Function can be Used if needed

Test Cases:
![Add comments Please!!! average WithPolicy(scores) (20 pts] Consider the following excerpt from](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f5002e32e5b_39766f5002dc69ac.jpg)
Python3
No str() please try to do it in a simplistic way (:
Add comments Please!!!
average WithPolicy(scores) (20 pts] Consider the following excerpt from a course syllabus: In order to reward improvement, I will replace one quiz score that is immediately followed by two higher scores. So, if you have a quiz that goes very badly, but your next two quizzes are each better than that bad quiz, / will replace that low quiz with the higher of the two scores immediately following it. If you have multiple "bad" quizzes that meet the criteria, I will replace the one that maximizes your point gain. Write the non-destructive function averageWithPolicy(scores) which takes as an argument a list of scores and returns the average of those scores after applying this policy. Consider the following examples: assert (averageWithPolicy ([42, 20, 40, 35, 50, 65]) == 47.0 assert (averageWithPolicy([25, 30, 20, 45, 40, 60, 70, 80, 90, 100]) == 59.0) The first example is 47 because the quiz to be replaced is the 35, and it will be replaced by a 65. That means we are finding the average of [42, 20, 40, 65, 50, 65) The second example is 59 because the quiz to be replaced is the 40, and it will be replaced by a 70. That means we are finding the average of (25, 30, 20.45, 70, 60, 70, 80, 90, 100) Hint: You don't actually need to find and replace anything in the list. Instead, you just need to find the largest difference among all candidates that meet the "lower before two higher" criteria. I recommend you create a helper function to do that. def nondestructiveRemoveRepeats (L): result=[ ] for elem in L: if elem not in result: result.append(elem) return result == def testAverageWithPolicy(): print("Testing averageWithPolicy(scores)...', end='') assert(averageWithPolicy([42, 20, 40, 35, 50, 65]) - 47) assert(averageWithPolicy([25, 30, 20, 45, 40, 60, 70, 80, 90, 100]) == 59) assert (averageWithPolicy([40, 20]) 30) assert(averageWithPolicy([40, 20, 10, 15, 9]) 18.8) print('Passed!') SE ==
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
