wats wrong in this code for finding standard deviation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)

10th Mar 2022, 10:14 AM
Krupa Varsha P
15 Answers
+ 2
Ok let me try it out
10th Mar 2022, 1:46 PM
Krupa Varsha P
+ 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
10th Mar 2022, 11:33 AM
Jayakrishna 🇮🇳
+ 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)]))
11th Mar 2022, 1:41 AM
Yawa
0
...(len(my_list))**0.5 print(int(a))
10th Mar 2022, 10:19 AM
Simba
Simba - avatar
0
nope not working
10th Mar 2022, 10:21 AM
Krupa Varsha P
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?
10th Mar 2022, 11:00 AM
Jayakrishna 🇮🇳
0
Nope its not working
10th Mar 2022, 11:16 AM
Krupa Varsha P
0
Is there asked to round the result or integer result?
10th Mar 2022, 11:23 AM
Jayakrishna 🇮🇳
0
Test case is hidden
10th Mar 2022, 11:25 AM
Krupa Varsha P
0
Sorry could u plz elaborate cant able to catch ur point
10th Mar 2022, 11:38 AM
Krupa Varsha P
0
Can you post full question..? Is this about find football players in range mean to standard deviation?
10th Mar 2022, 12:00 PM
Jayakrishna 🇮🇳
0
S
10th Mar 2022, 12:31 PM
Krupa Varsha P
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]))
10th Mar 2022, 12:37 PM
Jayakrishna 🇮🇳
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 ]))
10th Mar 2022, 12:47 PM
Simba
Simba - avatar
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
11th Mar 2022, 7:31 AM
Somil Khandelwal