'Python zscore calculation
I am in need of some help. I am completely new tp programming and I am trying to come up with a function that prints a zscore the greatest number, least number and the mean of the list. I can only get the number to print in an equation but not to be solved. I have to use raw python that calculate the score.
population = [14, 28, 96, 97, 21, 29, 29, 4, 58,
42, 25, 97, 49, 33, 75, 53, 14, 53,
45, 87, 75, 66, 62, 55, 57, 44, 44,
94, 19, 96, 12, 59, 86, 88, 61, 68,
37, 64, 19, 46, 68, 98, 19, 54, 65,
30, 1, 82, 76, 3]
def mean(data_set):
return sum(data_set)/len(data_set)
def stdev(data_set):
variance = sum([(integer - mean(population)) ** 2 for integer in data_set])/len(data_set)
return variance ** .5
def least(data_set):
return min(data_set)
def greatest(data_set):
return max(data_set)
def z_score(population):
zscore1 = f'{greatest(population)} - {mean(population)} / {stdev(population)}'
zscore2 = f'{least(population)} - {mean(population)} / {stdev(population)}'
zscore3 = f'{mean(population)} - {mean(population)} / {stdev(population)}'
return zscore1, zscore2, zscore3
print(z_score(population))
'''
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
