Array of house prices, calculate and output the percentage of houses that are within one standard deviation from the mean. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Array of house prices, calculate and output the percentage of houses that are within one standard deviation from the mean.

Please help! I've been struggling with this task. The problem is getting the percentage. I already tried summing up the total house prices and the results to get the percentage too, but it didn't work. ........................................................... import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) mean = np.mean(data) std = np.std(data) x = mean - std y = mean + std result = [] for i in result: if i > x and i < y: result.append(i) n = len(result) nd = len(data) answer = (n/nd)*100 print (answer) print ((len(result)/len(data))*100)

26th Aug 2021, 1:18 PM
Bello Abdullahi Ayodeji
Bello Abdullahi Ayodeji - avatar
3 Réponses
0
Thank you so much.... Can't believe I didn't see the mistake, almost gave me a headache
26th Aug 2021, 11:31 PM
Bello Abdullahi Ayodeji
Bello Abdullahi Ayodeji - avatar
0
for i in result: --> for i in data:
19th Apr 2022, 6:51 AM
Nguyen Khanh Toan
Nguyen Khanh Toan - avatar
0
import numpy as np data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000]) z = np.std(data) y = np.mean(data) low = y - z high = y + z count = 0 for i in data: if low < i < high: count = count + 1 result = (count/ len(data)) * 100 print (result )
1st Jul 2022, 2:06 PM
Najm Aarifeen