IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Foundations of Probability in Python

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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)
Modifica ed esegui il codice