# Trying to solve fancy house in python data structure

Here is the code i tried Don't know what is wrong with my code prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] x = sum(prices) y=len(prices) d=(x/y) print(len(prices)>d) Here is the question 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.

4/12/2021 7:08:43 AM

Simisola Osinowo14 Answers

New Answer#Try this prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] x = sum(prices) y=len(prices) d=(x/y) count = 0 for i in prices: if i > d: count+=1 print(count)

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. prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here mid_price = sum(prices)/ len(prices) hight_price = 0 for i in prices: if i> mid_price: hight_price+=1 print(hight_price)

prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here avg = sum(prices) / len(prices) print(sum(i > avg for i in prices))

average=sum(prices)/len(prices) x =(list(filter(lambda x: x> average,prices))) print(len(x))

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. Use sum(list) to calculate the sum of all items in the list and len(list) to get the number of items.

Ah OK, i think its task from data science, u need count of house more then x/y for this u can use loop for generate new list, or u can use filter. len(list(filter(lambda x: x>d,prices)))

try this code prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here avg = sum(prices)/len(prices) lst = 0 for i in prices: if i > avg: lst += 1 print(lst)

prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here total= sum([prices[x] for x in range(len(prices))])/len(prices) nbr=0 for x in prices: if x > total: nbr = nbr + 1 print(nbr)

prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here total = sum(prices) length = len(prices) avg= total/length above_avg_houses =[price for price in prices if price > avg ] print(len(above_avg_houses)) try this with list comprehension python