+ 1

Why my code is not correct

In python data science the basketball players problem I have written this code from math import sqrt players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players) / len(players) result = 0 for player in players: result += (mean - player)**2 variance = result / len(players) std = sqrt(variance) start = int(mean - std) end = int(mean + std) num_players = 0 for i in players : if i in range(start,end): num_players += 1 print(num_players)

5th May 2022, 4:58 PM
Asmaa Salih
Asmaa Salih - avatar
2 Respuestas
+ 4
Don't convert the start and end to integer. You are increasing the range of standard deviation by converting "start" and "end" to integer. Original start value is 178.63 something but when you convert it to integer, it becomes 178. Leave it as it is. Also, you need to change the line: "if i in range(start, end)" because range function don't accept float. Use, "if (i >= start) and (i <= end)"
5th May 2022, 5:47 PM
Sandeep
Sandeep - avatar
+ 4
Do not cast start or and to int. Leave it as it is.
5th May 2022, 5:02 PM
Lisa
Lisa - avatar