All problems
Discrete Expectation Value
Problem
The expectation of a discrete variable is sum_i x_i p_i.
Given the values and their probabilities (which sum to one), return E[X].
Hint
Weight each value by its probability.
Test cases
case 1
in: [[0,1],[0.5,0.5]]
expected: 0.5
case 2
in: [[1,2,3],[0.2,0.5,0.3]]
expected: 2.1
case 3
in: [[-1,0,1],[0.25,0.5,0.25]]
expected: 0
Starter codePython
def discrete_expectation_value(values, probs):
# Your code here
pass3 test cases · run your code against them in the editor