Question: Hey I need help with this question don't understand how to do it must use try and except in the code python cheers: Write a
Hey I need help with this question don't understand how to do it must use try and except in the code python cheers:

Write a function called get_mean(list_of_numbers) that takes a list of numbers as a parameter and returns the mean of the list. If the list is empty or it does not contain any valid values, then the function should return "ERROR: No valid values!". The function should validate the type of input. If the parameter is invalid, the function should return "ERROR: Invalid input!" If the list contains any invalid values, the function should ignore them and continue to do the calculation. Note: you *must* use the try... except syntax in your solution. For example, if the list contains the following values: my_list = [1.5, 2, 3, 4, 'NA', 2.5] then the function should return the value of 2.6. (i.e. (1.5+2+3+4+2.5)/5 = 2.6) For example: Test Result print(get_mean([1, 2, 3])) 2.0 print(get_mean(123)) ERROR: Invalid input! print(get_mean( [])) ERROR: No valid values ! my_list = (1.5, 2, 3, 4, 'NA', 2.5] 2.6 print(get_mean (my_list)) Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50%) 1 def get_mean(list_of_numbers): 2 try: 3 4. except: 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
