# 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 Osinowo11 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)

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))

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)