Last active
August 20, 2020 23:38
-
-
Save crizCraig/e8f0066d6301795b3d960c978cef196e to your computer and use it in GitHub Desktop.
Python 3 explanation of https://math.stackexchange.com/questions/15055/in-a-family-with-two-children-what-are-the-chances-if-one-of-the-children-is-a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In a family with two children, what are the chances, if **one** of the children is a girl, that both children are girls? | |
from random import random | |
n = 0 | |
c = 0 | |
for i in range(100000): | |
a = random() < 0.5 | |
b = random() < 0.5 | |
if a or b: # **one** implies _either_ child | |
n += 1 | |
if a and b: | |
c += 1 | |
print(c/n) # 1/3 | |
# In a family with two children, what are the chances, if **the youngest** is a girl, that both children are girls? | |
n = 0 | |
c = 0 | |
for i in range(100000): | |
a = random() < 0.5 | |
b = random() < 0.5 | |
if a: # Only **the youngest** is a girl | |
n += 1 | |
if b: | |
c += 1 | |
print(c/n) # 1/2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment