0

House prices

import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) """ You are given an array that represents house prices. Calculate and output the percentage of houses that are within one standard deviation from the mean. """ ##### """ To calculate the percentage, divide the number of houses that satisfy the condition by the total number of houses, and multiply the result by 100. """ https://code.sololearn.com/cDH9mSBk50jU/?ref=app https://code.sololearn.com/cDH9mSBk50jU/?ref=app

26th Oct 2021, 4:35 PM
Kiran Biradar
Kiran Biradar - avatar
5 ответов
+ 5
You must calculate mean and standard deviation (std). mean + std and mean - std are the borders of the prices within one std. Count all prices that are in, and make a percentage of it
26th Oct 2021, 7:03 PM
Paul
Paul - avatar
+ 4
What's the point to have test case result hidden? How one supposed to debug the code?
15th May 2022, 9:30 PM
Gwaka
+ 3
import numpy as np data = np.array([150000, 125000,320000,540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) #Calculating tha mean mean = sum(data)/len(data) #Calculating Standard Deviation st_dev = np.std(data) #Stablishing the first standard deviation mean1 = mean + st_dev mean2 = mean - st_dev #List with the values of the first STDEV y = [] for x in data: if (x >= mean2 and x <= mean1): y.append(x) #calculating the percentange z = round((sum(y)/sum(data))*100, 2) print("{}%".format(z))
25th Jan 2022, 9:08 PM
Leandro Carvalho
Leandro Carvalho - avatar
+ 1
Thank you 😊
27th Oct 2021, 2:24 AM
Kiran Biradar
Kiran Biradar - avatar