All problems
Expected Value
Problem
Compute the expected value of a discrete random variable:
E[X] = sum(values[i] * probabilities[i])
You may assume the probabilities sum to 1.
Test cases
case 1
in: [[1,2,3,4,5,6],[0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666,0.16666666666666666]]
expected: 3.5
case 2
in: [[0,1],[0.5,0.5]]
expected: 0.5
case 3
in: [[10,0],[0.1,0.9]]
expected: 1
Starter codePython
def expected_value(values, probabilities):
# Your code here
pass3 test cases · run your code against them in the editor