0
wats wrong in this code for finding standard deviation
my_list = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] a=(sum((x-(sum(my_list) / len(my_list)))**2 for x in my_list) / (len(my_list)-1))**0.5 print(a)
15 Réponses
+ 2
Ok let me try it out
+ 1
You are missing the point..
"You need to calculate and output **how many players are in the range of one standard deviation from the mean**"
Range in standard deviation from mean is : between mean+standard deviation, mean-standard deviation
+ 1
You seem to have your parenthesis mixed up. Try this to find the std deviation:
a = (sum((x - sum(my_list )/len(my_list))**2 for x in my_list)/len(my_list)) **0.5
#To find the range of players:
print(len([i for i in my_list if (sum(my_list)/len(my_list) - std_dev) < i < (sum(my_list)/len(my_list) + std_dev)]))
0
...(len(my_list))**0.5
print(int(a))
0
nope not working
0
#try this:
my_list = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190]
a=(sum((x-(sum(my_list) / len(my_list)))**2 for x in my_list) / (len(my_list)))**0.5
print(a)
#can you see expected result?
0
Nope its not working
0
Is there asked to round the result or integer result?
0
Test case is hidden
0
Sorry could u plz elaborate cant able to catch ur point
0
Can you post full question..? Is this about find football players in range mean to standard deviation?
0
S
0
The task is to find players in range between mean±standard deviation
Find mean, standard deviation.
Then find player height in range between mean-standard deviation and mean + standard deviation and print result...
edit: again try and see this next. .
my_list = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190]
mean = sum(my_list)/len(my_list)
stdv=(sum((x-(sum(my_list) / len(my_list)))**2 for x in my_list) / (len(my_list)))**0.5
print(len([i for i in my_list if mean-stdv<i< mean+stdv]))
0
a = (sum((x-sum(players)/len(players))**2 for x in players)/len(players))**0.5
This formula (a) returns the standard deviation. But, you need to calculate one standard deviation from the mean.
Add this
std_pos = sum(my_list)/len(my_list) + a
std_neg = sum(my_list)/len(my_list) - a
print(len([i for i in my_list if std_neg < i < std_pos ]))
0
import numpy as np
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190]
ply_mean=sum(players)/len(players)
ply_std=(sum([(v-ply_mean)**2 for v in players])/len(players))**0.5
low = ply_mean-ply_std
high = ply_mean+ply_std
count=len([v for v in players if low<v<high])
print(count)
Try this