# It's not necessary to define sample size start value outside of the loop as instruction stated

In the screen above, we are asked to create a for loop to generate samples of incremented sizes. One of the instruction is:

• To achieve that, you’ll need to increment the sample size by 29 for every new iteration. Note that you’ll first have to define the sample size with a value of 5 outside the loop.

While it’s a nice instruction, I find that you don’t have to

define the sample size with a value of 5 outside the loop.

In the for loop, all you need to do is increment sample size with `5+29*i` while `i` is the iteration in the `range(0,101)`

My Code:

``````mean = houses['SalePrice'].mean()
sampling_error = []
sample_range = []
for i in range(101):
sample_range.append(5+29*i)
sample = houses['SalePrice'].sample(5+29*i, random_state = i)
sample_mean = sample.mean()
sampling_error.append(mean - sample_mean)

plt.scatter(x = sample_range, y =sampling_error)
plt.axhline(y = 0)
plt.axvline(x = 2930)
plt.xlabel('Sample size')
plt.ylabel('Sampling error')
``````

I know there are a lot of mathematics majors in this community, just thought I’d mention it. 9 Likes