13 Coin flipping probability#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/mkyZ45KQYi4/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns

khanacademy

Coin flipping probability fig 1Coin flipping probability fig 2

flip = ['H', 'T']
def P(cond, total_lst):
    cond_lst = list(filter(cond, total_lst))
    return len(cond_lst) / len(total_lst), cond_lst
def P_in_a_row(p, n):
    return p**n
p_heads, _ = P(lambda x: x == 'H', flip)
p_tails, _ = P(lambda x: x == 'T', flip)
# P(at least one head in 3 flips) = 1 - P(TTT)
1 - P_in_a_row(p_tails, 3)
0.875
# P(at least one head in 10 flips) = P(not all tails in the 10 flips) = 1 - P(TTTTTTTTTT)
1 - P_in_a_row(p_tails, 10)
0.9990234375