Created
October 24, 2019 05:47
-
-
Save albertyumol/7b27fc2d18ba00bb59d2b84f54dfd431 to your computer and use it in GitHub Desktop.
Calculating conditional probabilities in Python.
This file contains 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
import random | |
def random_kid(): | |
return random.choice(['boy','girl']) | |
both_girls = 0 | |
older_girl = 0 | |
either_girl = 0 | |
random.seed(7) | |
for i in range(1000000): | |
younger = random_kid() | |
older = random_kid() | |
if older == 'girl': | |
older_girl += 1 | |
if older == 'girl' and younger == 'girl': | |
both_girls += 1 | |
if older == 'girl' or younger == 'girl': | |
either_girl += 1 | |
problem_one = both_girls/older_girl | |
problem_two = both_girls/either_girl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment