Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-341

Total Probability Two Partitions

Problem

For the partition {A, not A}, the law of total probability gives P(B) = P(B | A) P(A) + P(B | not A) P(not A).

Given P(B | A), P(A), and P(B | not A), return P(B).

Hint

Weight each conditional by the probability of its condition.

Test cases

case 1
in: [0.8,0.3,0.2]
expected: 0.38
case 2
in: [0.5,0.5,0.5]
expected: 0.5
case 3
in: [1,0.9,0]
expected: 0.9
Starter codePython
def total_probability_two_partitions(p_b_given_a, p_a, p_b_given_not_a):
    # Your code here
    pass

3 test cases · run your code against them in the editor