Question: Need help with python function Must use try/except The statistics library throws an exception in many cases where the incoming dataset is empty. Also older
Need help with python function
Must use try/except 
The statistics library throws an exception in many cases where the incoming dataset is empty. Also older versions of the library generated an error when you calculated the mode on a set of numbers that are evenly distributed. import statistics as stats numbers = [1,2,3,4] print("mode", stats.mode(numbers)) The library still generates an error if the incoming data is empty: numbers = [] print("mode", stats.mode(numbers)) Also the same error would be generated if you asked for the variance of a single number: numbers = [1] print("var", stats. variance (numbers)) Create a function named worry_free_mode that takes a list of numbers as its parameter, returns the value from statistics.mode unless there is a StatisticsError (see the docs). If there is an error, return None. Create a function named worry_free_var that takes a list of numbers as its parameter, returns the value from statistics. variance unless there is a StatisticsError (see the docs). If there is an error, return None
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
