# 자녀가 2명인 경우,
# A: 첫째가 딸인 경우
# B: 둘째가 아들인 경우
# C: 둘 다 딸인 경우
# A와 B가 독립 사건, A와 C는 종속 사건임을 증명
# P(A,B) == P(A) * P(B), P(A,C) != P(A) * P(C)
import random
child = ('boy', 'girl')
trials = 10_000
event_a = 0
event_b = 0
event_a_b = 0
event_c = 0
event_a_c = 0
for _ in range(trials):
first = random.choice(child)
second = random.choice(child)
if first == 'girl':
event_a += 1
if second == 'boy':
event_b += 1
if first == 'girl' and second == 'boy':
# 사건 A와 사건 B의 교집합
event_a_b += 1
if first == 'girl' and second == 'girl':
event_c += 1
if first == 'girl' and (first == 'girl' and second == 'girl'):
# 사건 A와 사건 C의 교집합
event_a_c += 1
p_a = event_a / trials
p_b = event_b / trials
p_a_b = event_a_b / trials
p_c = event_c / trials
p_a_c = event_a_c / trials
print(f'P(A,B) = {p_a_b}, P(A)P(B) = {p_a * p_b}')
print(f'P(A,C) = {p_a_c}, P(A)P(C) = {p_a * p_c}')
P(A,B) = 0.2494, P(A)P(B) = 0.2507004
P(A,C) = 0.251, P(A)P(C) = 0.1256004