Question: #My python program will not run! I ' m not sure why import math #You may not import any libraries other than math def calculate

#My python program will not run! I'm not sure why
import math
#You may not import any libraries other than math
def calculate(self):
return sum(self.dataset)/ len(self.dataset)
# Insert code to calculate and return the mean of the dataset.
class median:
def __init__(self, dataset):
self.dataset = dataset
def calculate(self):
sorted_data = sorted(self.dataset)
n = len(sorted_data)
if n %2==0:
mid1= sorted_data[n //2-1]
mid2= sorted_data[n //2]
return (mid1+ mid2)/2
else:
return sorted_data[n //2]
# Insert code to calculate and return the median of the dataset.
class stdev:
def __init__(self, dataset):
self.dataset = dataset
def calculate(self):
mean_value = mean (self.dataset).calculate()
n = len(self.dataset)
squared_diff_sum = sum((x - mean)**2 for x in self.dataset)
return math.sqrt(squared_diff_sum /(n -1))
# Insert code to calculate and return the sample standard deviation
# of the dataset.
class pstdev:
def __init__(self, dataset):
self.dataset = dataset
def calculate(self):
mean = mean(self.dataset).calculate()
n = len(self.dataset)
squared_diff_sum = sum((x - mean)**2 for x in self.dataset)
return math.sqrt(squared_diff_sum / n)
# Insert code to calculate and return the population standard
# deviation of the dataset.
data =[1,2,3,4,5]
mean_calculator = mean(data)
median_calculator = median(data)
stdev_calculator = stdev(data)
pstdev_calculator = pstdev(data)
print("Mean:", mean_calculator.calculate())
print("Median:", median_calculator.calculate())
print("Sample Standard Deviation:", stdev_calculator.calculate())
print("Population Standard Deviation:", pstdev_calculator.calculate())

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!