+ 2

Tell me mistakes. Calculate the range of one standard deviation.

players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players)/len(players) sqr = 0 for i in players: sqr += (i-mean)**2 std = sqr/len(list)**0.5 x = 0 for i in players: if i > mean-std and i < mean-std: x += 1 print(x)

6th Oct 2021, 6:21 PM
Bobby
10 Antworten
0
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players)/len(players) stdvar = (sum((v-mean)**2 for v in players)/len(players))**0.5 low, high = mean-stdvar,mean+stdvar count = len([v for v in players if low < v < high]) print(count)
6th Oct 2021, 6:44 PM
Bobby
+ 3
It's the first end of module project of the Python for Data Science course: "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."
6th Oct 2021, 7:45 PM
Simon Sauter
Simon Sauter - avatar
+ 2
You should put your code in the playground and save it. Then paste a link here so we can see it as you update it
6th Oct 2021, 6:38 PM
Slick
Slick - avatar
+ 1
Jayakrishna🇮🇳 Slick I suppose it is a task from the data science course
6th Oct 2021, 6:41 PM
Lisa
Lisa - avatar
+ 1
Bobby for the future: 1. Always include the task description. It's hard to help you when you don't tell people what you're trying to do. 2. Post your code in the code playground and link it here. It's far easier to figure out what is going on when you can run the code and "play around" with it.
6th Oct 2021, 7:52 PM
Simon Sauter
Simon Sauter - avatar
0
'list' is a type and therefore has no length. 'i' cannot be less than AND greater than another value Bobby i didn't know that i told you impropely. I'm not really sure what the program does, but those lines will cause issues with your expected output.
6th Oct 2021, 6:31 PM
Slick
Slick - avatar
0
Can u tell me properly?
6th Oct 2021, 6:31 PM
Bobby
0
additionally: std is (sqr/len(...))**0.5 (You forgot the outer brackets)
6th Oct 2021, 6:34 PM
Lisa
Lisa - avatar
0
It's not passing the test
6th Oct 2021, 6:37 PM
Bobby
0
@Bobby You are using len(list) but you may need len(players) for std calculations... .. And if condition in last loop never comes true. What you need to calculate actually?
6th Oct 2021, 6:40 PM
Jayakrishna 🇮🇳