12345 - Python_mooc_1   

Description

Write a Python function to compute the average of a sequence of numbers after
discarding m lowest and n highest scores. If the sequence is empty before or after
cropping, then return None

''' you should use the template of following.'''

import ast
 
def CroppedAverage(LdropLow=0dropHigh=None):
    #coding on here
    #coding on here
    #coding on here
 
if __name__ == '__main__':
    L = ast.literal_eval(input())
    for i in [(L,), (L, 21), (L, 34)]:
        print(f'CroppedAverage{i}=', CroppedAverage(*i))

Input

[3, 15, 13, 9, 11, 7, 5]

Output

>>> CroppedAverage(L) # works like a regular average
9.0
>>> CroppedAverage(L, dropLow=2, dropHigh=1) # drop 3, 5, 15
10.0
>>> CroppedAverage(L, dropLow=3, dropHigh=4) # drop all
None

Sample Input  Download

Sample Output  Download

Tags

else return; // else return; // else return



Discuss