Get startedGet started for free

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.

This exercise is part of the course

Foundations of Probability in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the bernoulli object from scipy.stats
from ____ import ____

# Set the random seed to reproduce the results
np.____.____(42)

# Simulate one coin flip with 35% chance of getting heads
coin_flip = ____.rvs(p=____, size=____)
print(coin_flip)
Edit and Run Code