Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-379

Law of Total Expectation Two Cases

Problem

For the partition {A, not A}: E[X] = E[X | A] P(A) + E[X | not A] P(not A).

Given the two conditional expectations and P(A), return E[X].

Hint

Average the conditional means with the partition probabilities.

Test cases

case 1
in: [10,0.3,2]
expected: 4.4
case 2
in: [5,0.5,5]
expected: 5
case 3
in: [0,0.8,100]
expected: 19.999999999999996
Starter codePython
def law_of_total_expectation_two_cases(mean_given_a, p_a, mean_given_not_a):
    # Your code here
    pass

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