1. Learn
  2. /
  3. Courses
  4. /
  5. Foundations of Probability in Python

Exercise

Flipping coins

This exercise requires the bernoulli object from the scipy.stats library to simulate the two possible outcomes from a coin flip, 1 ("heads") or 0 ("tails"), and the numpy library (loaded as np) to set the random generator seed.

You'll use the bernoulli.rvs() function to simulate coin flips using the size argument.

You will set the random seed so you can reproduce the results for the random experiment in each exercise.

From each experiment, you will get the values of each coin flip. You can add the coin flips to get the number of heads after flipping 10 coins using the sum() function.

Instructions 1/3

undefined XP
  • 1

    Import bernoulli from scipy.stats, set the seed with np.random.seed(). Simulate 1 flip, with a 35% chance of heads.

  • 2

    Use bernoulli.rvs() and sum() to get the number of heads after 10 coin flips with 35% chance of getting heads.

  • 3

    Using bernoulli.rvs() and sum(), try to get the number of heads after 5 flips with a 50% chance of getting heads.