We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
since the family has 2 childrens and one of them is boy. however, they did not mentioned whether first born is a boy or second born is a boy.
so the possibilities are:
S1 = ['B','G'] # considering first children born is boy
S2 = ['G','B'] # considering first children born is girl
sample_space = [(s1,s2) for s1,s2 in product(S1,S2) if [s1,s2]!=['G','G']]
sample_length = len(sample_space)
filtered = [(s1,s2) for s1,s2 in product(S1,S2) if (s1==s2) and [s1,s2]!=['G','G']]
filtered_length = len(filtered)
print(filtered)
print(filtered_length)
print(sample_length)
print(Fraction(filtered_length, sample_length))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 3: Conditional Probability
You are viewing a single comment's thread. Return to all comments →
from itertools import product
from fractions import Fraction
since the family has 2 childrens and one of them is boy. however, they did not mentioned whether first born is a boy or second born is a boy. so the possibilities are:S1 = ['B','G'] # considering first children born is boy
S2 = ['G','B'] # considering first children born is girl
sample_space = [(s1,s2) for s1,s2 in product(S1,S2) if [s1,s2]!=['G','G']]
sample_length = len(sample_space)
filtered = [(s1,s2) for s1,s2 in product(S1,S2) if (s1==s2) and [s1,s2]!=['G','G']]
filtered_length = len(filtered)
print(filtered)
print(filtered_length)
print(sample_length)
print(Fraction(filtered_length, sample_length))