Lesson 4 of 15
Conditional Probability
Updating on Evidence
Conditional probability is the probability of given that has occurred:
Conditioning on reduces the sample space to only outcomes where holds.
# Roll two dice. Given the sum > 7, what is P(first die = 6)?
# Outcomes where sum > 7: (2,6),(3,5),(3,6),(4,4),(4,5),(4,6),(5,3)...(6,6) → 15 outcomes
# Of these, first die = 6: (6,2),(6,3),(6,4),(6,5),(6,6) → 5 outcomes
# P(first=6 | sum>7) = 5/15 = 1/3
p_ab = 5/36 # P(first=6 AND sum>7)
p_b = 15/36 # P(sum > 7)
print(round(p_ab / p_b, 4)) # 0.3333
Chain Rule
This extends to any number of events:
Your Task
Implement conditional(p_ab, p_b) that returns , rounded to 4 decimal places.
Pyodide loading...
Loading...
Click "Run" to execute your code.