Calculate SD : | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Calculate SD :

# Statement : ''' players_heights = [180,172,178,185,190,195,192,200,210,190] The given code includes a list of heights for various basketball players. You need to calculate and output how many players are in the range of one standard deviation from the mean. '''

10th Sep 2021, 1:40 PM
Aditya Nijave
Aditya  Nijave - avatar
4 Antworten
+ 2
variance = for_variance / N
10th Sep 2021, 3:33 PM
Simba
Simba - avatar
+ 1
Aditya Nijave Where is attempts?
10th Sep 2021, 1:49 PM
A͢J
A͢J - avatar
0
A═óJ - S═čo═čl═čo═čH═če═čl═čp═če═čr═č players_heights = [180,172,178,185,190,195,192,200,210,190] sum_of_total_players_height = 0 for players_height in players_heights: sum_of_total_players_height += players_height N = len(players_heights) mean = sum_of_total_players_height / N for_variance = 0 for players_height in players_heights: as_required_fig = (players_height - mean)**2 for_variance += as_required_fig variance = for_variance / (N-1) SD = variance**0.5 for_range = [] lower_limit = mean - SD upper_limit = mean + SD for players_height in players_heights: if lower_limit <= players_height <= upper_limit: for_range.append(players_height) spread_out = len(for_range) print(f"{spread_out}")
10th Sep 2021, 2:35 PM
Aditya Nijave
Aditya  Nijave - avatar
0
Aditya Nijave No need to write this much logic. You have already calculated mean, just filter list on that mean and get new list like this: list1 = [i > mean for i in players] #this will return a list of True, False print (sum(list1)) Note: You can directly get sum of list using sum function, no need to use loop
10th Sep 2021, 3:01 PM
A͢J
A͢J - avatar