Question: Using basic python and information provided below, assist with the analysis function of this program: import math def square(number): number = number**2 return number def
Using basic python and information provided below, assist with the analysis function of this program:
import math
def square(number):
number = number**2
return number
def average(numbers: list) -> float:
average = sum(numbers) / len(numbers)
return average
def average_complain(numbers: list) -> float:
try:
average = sum(numbers) / len(numbers)
return average
except TypeError:
return math.nan
except ZeroDivisionError:
return math.nan
def standard_deviation(numbers: list) -> float:
mean = average(numbers)
run_sum = 0
for i in numbers:
run_sum += square(i - mean)
std_dev = math.sqrt(run_sum / (len(numbers) - 1))
return std_dev
def get_outliers(numbers: list) -> list:
outlier = []
ranked_list = sorted(numbers)[1:-1]
avg = average(ranked_list)
std_dev = standard_deviation(ranked_list)
lower_limit = avg - 2.5 * std_dev
upper_limit = avg + 2.5 * std_dev
for item in numbers:
if item <= lower_limit or item >= upper_limit:
outlier.append(item)
return outlier
def remove_outliers(numbers: list) -> list:
outlier = get_outliers(numbers)
new_list = []
for item in numbers:
if item not in outlier:
new_list.append(item)
return new_list
def sum_of_multiples(multiples: list) -> float:
try:
run_sum = 0
for multiple in multiples:
mult_split = multiple.split()
if len(mult_split) == 1:
number = int(mult_split[0])
run_sum += number
if len(mult_split) == 2:
number1 = int(mult_split[0])
number2 = int(mult_split[1])
run_sum += number1 * number2
return run_sum
except IndexError:
return 0
except AttributeError:
return 0
except TypeError:
return 0
def analysis():
'''
You first print this string:
'Enter a series of numbers. Press ENTER alone when finished. '
Then you wait in a loop while the user enters numbers.
If they enter nothing, then you're done accepting numbers.
If they enter something that can't be cast as an integer, then just ignore it and keep waiting.
Finally, if they enter a number, cast it as an integer and store it in a list.
Once you have the list, present it to the user, use your get_outliers() function to show the user a list
of outliers, and then use your remove_outliers() function to remove them from the data.
then, you are to use the outlier-removed numbers to indicated the following information
the mean -- use your average() function
the standard deviation -- use your standard_deviation() function
the variance -- that's just the square of the standard deviation, so use your square() function
the minimum and maximum -- luckily, Python provides the min() and max() functions!
the lower quartile -- the bottom 1/4th of numbers from the ranked (aka ordered) data
the upper quartile -- the top 1/4th of numbers from the ranked (aka ordered) data
The way you are to format all of this is shown below based on an example list of numbers.
E.g., if you copy/paste this stack of number into your program (tabbed all the way to the left for easy copying),
343
939
495
2233
897
32
898
877
499
534
402
522
777
666
Your program should output the following (formatted exactly as shown):
Data Entered
------------
Numbers: [343, 939, 495, 2233, 897, 32, 898, 877, 499, 534, 402, 522, 777, 666]
Outliers: [2233, 32]
Numbers w/o Outliers [343, 939, 495, 897, 898, 877, 499, 534, 402, 522, 777, 666]
Analysis (outliers removed from data)
-------------------------------------
Mean = 654.083
StdDev = 214.511
Variance = 46015.174
Minimum = 343
Maximum = 939
Lower Quartile = [343, 402, 495]
Upper Quartile = [897, 898, 939]
Done
Note: With the exception of general exceptions (see note at very top of file), you can
use try/except as you see fit in this solution.
Note: If no numbers are provided and your program ends up with an empty list of numbers, your entire output
should just be this:
Data Entered
------------
Numbers: []
Done
'''
if __name__ == '__main__':
# This is the only line you CANNOT remove or edit
# Add your function calls here to try out your code.
analysis()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
