+ 4

[SOLVED] Basketball players problem

import statistics players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] statistics.stdev(players) # std is 11.1 , mean is 189.2 So, I need to output how many players are between (189.2 - 11.1) to (189.2 + 11.1)

16th Mar 2021, 12:05 PM
Kristo Kallfa
Kristo Kallfa - avatar
53 ответов
+ 89
The correct answer is: 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)
27th Mar 2021, 12:35 AM
kensy Nicolle Gutierrez Flores
kensy Nicolle Gutierrez Flores - avatar
+ 13
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] import numpy as np mean = np.mean(players) standard_deviation = np.std(players) variance = np.var(players) result = 0 for i in players: if i >= mean-standard_deviation and i <= mean+standard_deviation: result += 1 print(result)
9th May 2021, 6:28 AM
R Krishnan Vijay
R Krishnan Vijay - avatar
+ 11
import numpy as np players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] data = np.array(players) m = np.mean(data) std = np.std(data) under = m - std above = m + std fit = data[(data>under) & (data<above)] print(len(fit))
1st Nov 2021, 8:55 AM
Ventsislav Georgiev
Ventsislav Georgiev - avatar
+ 4
yes, you must loop over the array and count how many values matches the conditions ;) finally, just output the count...
16th Mar 2021, 2:32 PM
visph
visph - avatar
+ 4
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players) / len(players) std = (sum([(i - mean) ** 2 for i in players]) / len(players)) ** 0.5 print(len(list(filter(lambda x: mean - std < x < mean + std, players))))
2nd Jul 2021, 10:10 AM
郭彥均
郭彥均 - avatar
+ 3
All it was wrriten was just :”players = [180,172,178,185,190,195,192,200,210,190] My code is : import statistics players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = (180 + 172 + 178 + 185 + 190 + 195 + 192 + 200 + 210 + 190) / 10 statistics.stdev(players) So, I know the mean and the std, all I have to do now is to check how many players are in that range... like I have to use smth like for players in range... idk...any idea?
16th Mar 2021, 2:29 PM
Kristo Kallfa
Kristo Kallfa - avatar
+ 1
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players)/len(players) std = (sum((height-mean)**2 for height in players)/len(players))**0.5 high = mean+std low=mean-std total = len([height for height in players if low < height < high]) print(total)
14th Feb 2022, 9:49 AM
Alcino Castelo
+ 1
players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] total=0 mean=0 for player in players: total=total + player mean=total/len(players) squared_differences = [ (player-mean)**2 for player in players ] total_squared_differences=0 for squared_difference in squared_differences: total_squared_differences=total_squared_differences + squared_difference variance=total_squared_differences/len(players) standard_deviation=variance**0.5 low, high = mean-standard_deviation,mean+standard_deviation count = len([player for player in players if low < player < high]) print(count)
17th Nov 2022, 1:51 AM
Benjamin Fadina
Benjamin Fadina - avatar
+ 1
This is how I solved it: import math players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players)/len(players) total = 0 for x in players: x = (x-mean)**2 total += x avgresult = total/len(players) std_dev = math.sqrt(avgresult) results = 0 for p in players: if mean-std_dev < p and mean+std_dev > p: results = results + 1 print(results)
18th Jan 2023, 1:00 AM
Chris
Chris - avatar
0
well, you're right... where is your coding attempt? we need to see what you've tried so far to be able to help ^^
16th Mar 2021, 2:18 PM
visph
visph - avatar
0
Thank You!
16th Mar 2021, 2:38 PM
Kristo Kallfa
Kristo Kallfa - avatar
0
Coalemus because your for loop should throw an error, as you're trying to iterate in a range of float (decimal) values, while it expect intergers (whole numbers)... anyway, you should post your own question to be helped further ^^
22nd Mar 2021, 9:08 PM
visph
visph - avatar
0
Oh my bad, thanks anyway!
22nd Mar 2021, 9:10 PM
Coalemus
0
kensy Nicolle Gutierrez Flores kindly stop spamming others threads, and rather post your own question in a brand new thread, by following the Q&A guidelines (accurate and short title, useful tags and explanation of your specific problem in the description field with your code attempt provided)...
24th Mar 2021, 5:29 AM
visph
visph - avatar
0
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] mean=sum(players)/len(players) var=sum((x-mean)**2 for x in players) std=var**0.5 for players in range(int(mean-std),int(mean+std)): print(players) what might be the issue with this code??