+ 2
Python, Basketball players
Can someone tell me what I have done wrong? (my code is below). 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. players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] x=0 for i in range(len(players )): x+=players[i] mean=x/len(players) y=0 for i in range(len(players)): y+=(players[i]-mean)**2 var=(y/len(players)) std=var**(1/2) for i in range(len(players )): if players[i]>(mean-std) and players[i]<(mean+std): print(players[i])
5 Answers
+ 3
Zotta you are welcome. It also happens to me sometimes.
+ 1
You should declare
numPlayers = 0
And in the last loop and the if add them
numPlayers +=1
Instead print the each player
And after the loop print the number numPlayers.
0
JaScript ,thanks, seems I wasn't so attentive, like being in rush. Anyway thanks for helping
- 1
You need to print the scores that are within one standard deviation from the mean, not the std itself.
For example if the mean is 200 and the std is 10.
Then 190, 191, 192, 193 ... 201, 202, 203, 204 up to 210 is within one standar deviation.
Hint: Use for loop to iterate each scores and have conditions that checks if the score is within one std.
- 1
Eve yeah,i figured it out after posting this question, but even I have changed that part of code anyway it still doesn't work. (I have changed the code in post)