Congratulations! You now know how to run a binomial hypothesis test using a SciPy function — or by simulating it yourself! This will serve you well as a data scientist because it will enable you to investigate what’s going on if pre-written functions return surprising results. You also now have a conceptual understanding of how a binomial test works and what questions it aims to answer. To summarize, here are some of the things you’ve learned about hypothesis tests in general:

  • All hypothesis tests start with a null and alternative hypothesis

  • Outcomes of a hypothesis test that might be reported include:

    • confidence intervals
    • p-values
  • A hypothesis test can be simulated by:

    • taking repeated random samples where the null hypothesis is assumed to be true
    • using those simulated samples to generate a null distribution
    • comparing an observed sample statistic to that null distribution


As a final exercise, the solution code for the previous exercise is available to you in script.py. As a challenge, see if you can re-write the simulation-based binomial test function so that it has an input named alternative_hypothesis that can be equal to 'less', 'not_equal', or 'greater'. Then change the function so that it performs the appropriate one- or two-sided test for the alternative hypothesis provided. Solution code is available to you in solution.py if interested.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?