i know calculate the average price of the houses.i just want to know how to output the number of houses that have a price that i | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

i know calculate the average price of the houses.i just want to know how to output the number of houses that have a price that i

You are analyzing house prices. The given code declares a list with house prices in the neighborhood. You need to calculate and output the number of houses that have a price that is above the average. To calculate the average price of the houses, you need to divide the sum of all prices by the number of houses. prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here

27th Feb 2021, 4:48 PM
Lion me
Lion me - avatar
7 Answers
+ 3
print(len([i for i in data if i > (np.mean(data) - np.std(data)) and i < (np.mean(data) + np.std(data))]) / len(data) * 100)
19th Apr 2021, 9:49 AM
Yurii Ostapenko
Yurii Ostapenko - avatar
+ 2
thanks
28th Feb 2021, 8:12 AM
Lion me
Lion me - avatar
+ 1
You can use for loop to iterate each element, then use condition inside. If a number/price is greater than the average then print it. for price in prices: if price > average: print(price)
27th Feb 2021, 4:52 PM
noteve
noteve - avatar
+ 1
#your code of average: #average=... print(len(list(filter(lambda n: n>average, prices))))
27th Feb 2021, 5:09 PM
Shadoff
Shadoff - avatar
0
Lion Fret kindly tag at least target language in your question (you could edit it) tip: to compute average, sum up all prices and divide the result by prices length ;)
27th Feb 2021, 7:31 PM
visph
visph - avatar
0
I have written the code but not sure where I am wrong.. prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] avg=int(sum(prices)/len(prices)) list1=[] for i in prices: if i>avg: list1.append(i) print(list1)
27th Mar 2021, 10:35 AM
Somnath Das
Somnath Das - avatar
0
prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here - number of houses that have a price that is above the average. average = sum(prices) / len(prices) cont = 0 for n in prices: if n > average: cont+=1 print(cont)
26th Feb 2022, 8:11 AM
Liria
Liria - avatar