+ 3
This is my attempt what's the mistake ?
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. ATTEMPT :players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] a = (1892/10) total = 29229 average = 29229/10 std = 2922.9 sqd = 54 x = list(range(a,sqd)) print(x)
4 odpowiedzi
+ 6
Codemurai
Get mean value using this formula
mean = sum(players) / len(players)
And count players whose height is greater than mean value like this
print (sum(i > mean for i in players))
+ 3
🅰🅹 (Challenge Accepted)
Thanks, ❤️
0
Hey there i have some suggestion for you.
python
Copy code
import math
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190]
# Calculate mean
mean = sum(players) / len(players) https://www.tellhappystar.org/
# Calculate standard deviation
std = math.sqrt(sum((x - mean) ** 2 for x in players) / len(players))
# Calculate the range of one standard deviation from the mean
lower_bound = mean - std
upper_bound = mean + std
# Count the players within one standard deviation
count = sum(lower_bound <= x <= upper_bound for x in players)
# Output the result
print("Number of players within one standard deviation from the mean:", count)
In this updated code:
We import the math module to access the square root function.
The mean is calculated correctly by summing all the heights and dividing by the number of players.
The standard deviation is calculated using the formula, taking the square root of the average squared differences from the mean.
The lower and upper bounds for one standard deviation are determined by subtracting and adding the standard deviation from the mean, respectively.
We use a list comprehension and the sum function to count the number of players within the range of one standard deviation from the mean.
Finally, we output the result.
Thanks and regards
JohnClore
0
Get mean value using this formula
mean = sum(players) / len(players)
And count players whose height is greater than mean value like this
print (sum(i > mean for i in players))
<a href="https://crediblebhs.online/">CredibleBH</a>