Please post full code in Python coding Your program needs to
*Please post full code* in Python coding
Your program needs to implement the following functions:
def calcMean (scores, count)
// Where scores is an an array/list of integers and
// count is the number of items in the array
// mean is essentially the same as the average.
// return the mean of the data in scores as a float
def calcMedian (scores, count)
// Calculate the median value for the data in scores
// Median is middle value if the number of items is odd
// or the average of the middle two values if the number
// of items is even.
def calcVariance (scores, count)
// Calculate the variance value for the data in scores
// variance is determined using the formula:
the sum of the square of the values / count
- square of the sum of the values / square of the count
def calcStdDev (variance)
// Calculate the standard deviation value for the data in scores
// standard deviation is the square root of the variance
def Histogram ()
// Print a histogram of the data in scores
// the bar chart in chapter 6.10 will give you a
// good starting point.
You will also need to provide a main program to exercise the functions and
a few sample data sets that you use to test the program.
--Thank you!
Solution
from math import sqrt
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
def calcMean(scores,count):
return float(sum(scores))/count
def calcMedian(scores,count):
sortedLst = sorted(scores)
index = (count - 1) // 2
if (count % 2):
return sortedLst[index]
else:
return (sortedLst[index] + sortedLst[index + 1])/2.0
def calcVariance(scores, count):
variance = 0
for i in scores:
variance += (calcMean(scores,count) - scores[i-1]) ** 2
return variance / count
def calcStdDev(scores,count):
sum = 0
mn = calcMean(scores,count)
for i in range(count):
sum += pow((scores[i]-mn),2)
return sqrt(sum/count-1)
def Histogram(scores):
x=scores
data = [go.Histogram(x=x)]
py.iplot(data)
def main():
print(calcMean([1,2,3,4],4))
print(calcMedian([1,2,3,4],4))
print(calcVariance([1,2,3,4],4))
print(calcStdDev([1,2,3,4],4))
if __name__ == \'__main__\':
main()

