Skip to content

Instantly share code, notes, and snippets.

@eLtronicsVilla
Created May 25, 2019 07:25
Show Gist options
  • Save eLtronicsVilla/5a5ad50d174d5791bee741e22e35ed9b to your computer and use it in GitHub Desktop.
Save eLtronicsVilla/5a5ad50d174d5791bee741e22e35ed9b to your computer and use it in GitHub Desktop.
import random
def bernoulli_trial(p):
return 1 if random.random() < p else 0
def binomial(n,p):
return sum(bernoulli_trial(p) for _ in range(n))
# Suppose this problem, there are 9 people selected (n = number of trials = 9). The probability of success is 0.62.
print(binomial(9,0.62))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment