Open oldoc63 opened 2 years ago
Notice that two of the three values that go into the stats.binomial.pmf() method are the parameters that define the binomial distribution: n represents the number of trials and p represents the probability of success.
Change the scaffolded code to calculate the probability of observing 3 heads in 10 fair coin flips. Save this probability to prob_1.
Using the same logic, calculate prob_2 to be the probability of observing 7 heads out of 20 fair coin flips. However, this time, directly input values into the stats.binomial.pmf() method. Then print prob_2.
The binom.pmf() method from the scipy.stats library can be used to calculate the PMF of the binomial distribution at any value. This method takes 3 values:
For example, suppose we flip a fair coin 10 times and count the number of heads. We can use the binom.pmf() function to calculate the probability of observing 6 heads as follows: