+ 1
Why does this code not produce the desired result? (Python for Data Structures Exercise 12)
4 Answers
+ 2
Per Bratthammar sir I am still getting same answer....see revised code !!!
+ 2
Per Bratthammar Hi again đ
yes same problem link in question (my code)
+ 1
# Hi, Sanjay Kamath !
# You can compare your code to these two codes, if you want.
# Iâm not shure, but the values reminds me of exercise 12 from Python for Data Science:
import numpy as np
data = np.array([150000, 125000, 320000, 540000, 200000, 120000, 160000, 230000, 280000, 290000, 300000, 500000, 420000, 100000, 150000, 280000])
avg = np.mean(data)
dev = np.std(data)
min = avg - dev
max = avg + dev
inv_less = data[data < min]
inv_more = data[data > max]
size_data = data.size
size_inv = size_data - (inv_less.size + inv_more.size)
ratio = size_inv / size_data
percent = ratio * 100
print(percent)
# But the calculatoon reminds me of exercise 10.2 in Python Data Structures:
prices = [125000, 78000, 110000, 65000, 300000, 250000, 210000, 150000, 165000, 140000, 125000, 85000, 90000, 128000, 230000, 225000, 100000, 300000]
avg = sum(prices) / len(prices)
cnt = 0
for p in prices:
if p > avg: cnt += 1
print(cnt)
+ 1
Hi, again Sanjay Kamath !
Is the problem you try to solve 10.2 Fancy Houses in Python for Data Structures?
A tip is to write your codes so they can handle different input data (list sizes). The second of the codes in my last post will solve that problem.
Can you please post the problem formulation, so I can read it?