0

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.

12th Apr 2021, 7:08 AM
Simisola Osinowo
Simisola Osinowo - avatar
16 Respostas
+ 5
#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)
12th Apr 2021, 8:02 AM
Simba
Simba - avatar
+ 2
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)
6th Dec 2021, 3:46 PM
Maksym
Maksym - avatar
+ 1
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))
11th Sep 2021, 2:00 PM
Challen Wang
Challen Wang - avatar
+ 1
average=sum(prices)/len(prices) x =(list(filter(lambda x: x> average,prices))) print(len(x))
1st Oct 2021, 7:46 AM
jiaqi chen
jiaqi chen - avatar
+ 1
prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here # get average price from the list averagePrice = sum(prices) / len(prices) # get prices above the average price aboveAverage = filter(lambda price: price > averagePrice, prices) # turn the aboveAverage into a list and print the lenght print(len(list(aboveAverage)))
12th Apr 2023, 12:05 AM
rhntp
rhntp - avatar
0
U need mean ± standard mean >=
12th Apr 2021, 7:29 AM
Илья Мирошник
Илья Мирошник - avatar
0
And for percent * 100
12th Apr 2021, 7:29 AM
Илья Мирошник
Илья Мирошник - avatar
0
I don't understand what you mean
12th Apr 2021, 7:31 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
I mean, you haven't read the conditions of task accurately enough
12th Apr 2021, 7:38 AM
Илья Мирошник
Илья Мирошник - avatar
0
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.
12th Apr 2021, 7:39 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
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)))
12th Apr 2021, 8:01 AM
Илья Мирошник
Илья Мирошник - avatar
0
Thanks it worked
12th Apr 2021, 8:12 AM
Simisola Osinowo
Simisola Osinowo - avatar
0
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)
28th May 2021, 4:53 AM
Abhishek Biswas
Abhishek Biswas - 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 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)
11th Sep 2021, 7:43 PM
guenaizi abdelkader
guenaizi abdelkader - 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 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
30th May 2022, 6:58 PM
R.G.I.T.B Jayarathne
0
prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000] #your code goes here sum_of_list = sum(prices) total_list = len(prices) average_price = sum_of_list/total_list new_list = 0 for i in prices : if i > average_price: new_list += i print(len(str(new_list)))
2nd Dec 2022, 9:15 AM
Pareshkumar Chaudhari