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  Need help with python function Must use try/except The statistics library

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!