+ 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. '''
4 Respostas
+ 2
variance = for_variance / N
+ 1
Aditya Nijave
Where is attempts?
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}")
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