FAQ: Learn Sample Size Determination with SciPy - Sample Size of a Survey

This community-built FAQ covers the “Sample Size of a Survey” exercise from the lesson “Learn Sample Size Determination with SciPy”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Data Science
Analyze Data with Python

FAQs on the exercise Sample Size of a Survey

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi, I don’t get well.
If we want to conduct a survey at exact town why should we care about population of the whole world (100.000). If for population size we can take 1700. Maybe the preferences of this city is specific. Thank you in advance!


I also have the same doubt. Hopefully somebody can clarify it.

1 Like

I also would like to know why

1 Like

Same here. Can someone help us?

Same doubt here too , please answer

I’ve never seen a member of Codecademy’s team respond to these threads.

In any event, I came here to refute that margin_of_error is meant to be 4. 4% would be 0.04.

I think to decide upon the population size as a shop owner, you wouldn’t consider only the people from your town as customers. For example, a customer can come in from out of town. So you want a large population size.

1 Like

The calculator for this exercise is written in JavaScript. I tried to write it in Python:

from scipy.stats import norm

def min_samples(conf_level, proportion, margin, population_size):

  # z-score for confidence level
  z = norm.isf((1- conf_level) / 2)

  # calculate the sample size
  num_samples = proportion * (1 - proportion) * ((z / margin) ** 2)

  # update according to population size
  num_samples = num_samples / (1 + (num_samples - 1) / population_size)

  return round(num_samples)

print(min_samples(0.95, 0.4, 0.04, 100000))  # 573.0

This is quite a leap to go from 1700 people in Vancucumber, to 100,0000. The same problem has been haunting me for the previous few slides in this lesson. I do not see how the discussion goes from sample size recommendations for 8 billion people should be equivalent to about 100,000, let alone why the survey designer would select a sample size of 100,000 for an unlisted base value, or in this case 1700 people in a town population. Sounds like the lesson could use a tune up.