0
Can not pass internal test. In to variance range.
Hello everyone, dear friends, I need a help below text of task and my code. Text of task: 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. My code: players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] count = 0 accum = 0 variance = 0 new_players = [] for i in players: count = count + 1 accum = accum + i mean = accum / count for j in players: variance = variance + (mean - j)**2 variance = (variance/count)**1/2 min_value = mean - variance max_value = mean + variance for i in players: if i > min_value and i < max_value: new_players.append(i) print(len(new_players))
4 odpowiedzi
+ 7
variance = (variance/count)**1/2 is similar to ((variance/count)**1)/2 = (variance/count)/2
Try doing this instead
variance = (variance/count)**(1/2)
+ 3
Lyapunov Alexander
Just a tip:
python has a sum() function.
mean = sum(players) / len(players)
+ 1
Simba
Thank you, yes... **(1/2) is correct decision!
+ 1
Denise Roßberg
Okay, great. It is very useful tip ;-)