- 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
7 odpowiedzi
+ 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)
+ 2
thanks
+ 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)
+ 1
#your code of average:
#average=...
print(len(list(filter(lambda n: n>average, prices))))
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 ;)
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)
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)