# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import random


def two_flips(num_sims=10000):
    coins=['fair','fair','2head']
    heads_count1=0
    heads_count2=0
    for sim in range(num_sims):
        coin=random.choice(coins)
        if coin=='fair':
            faces=['H','T']
        else:
            faces=['H','H']
        coin1_face=random.choice(faces)
        if coin1_face =='H':
            heads_count1+=1
            coin2_face = random.choice(faces)
            if coin2_face == 'H':
                heads_count2+=1
    print("Prob. of heads on second flip given heads on first flip is",
          heads_count2/heads_count1)


two_flips()


# (Verified analytically.) 
#
# $$
# P(H_1) = 2/3
# $$
#
# $$
# P(H_1 \cap H_2) = 1/2
# $$

def two_flips(num_sims=10000):
    coins=['fair','2head','2head']
    heads_count1=0
    heads_count2=0
    for sim in range(num_sims):
        coin=random.choice(coins)
        if coin=='fair':
            faces=['H','T']
        else:
            faces=['H','H']
        coin1_face=random.choice(faces)
        if coin1_face =='H':
            heads_count1+=1
            coin2_face = random.choice(faces)
            if coin2_face == 'H':
                heads_count2+=1
    print("Prob. of heads on second flip given heads on first flip is",
          heads_count2/heads_count1)


two_flips(100000)

# (Verified analytically)
#
# $$
# P(H_1)=5/6
# $$
#
# $$
# P(H_1 \cap H_2) = 3/4
# $$
#
# $$
# P(H_2|H_1) = 9/10
# $$



StarcoderdataJupyterScriptsDedupFiltered