Expected Value: A Probability-Weighted Average

Probability and StatisticsEasy+10 XP+10

Expected Value: A Probability-Weighted Average

The expected value is the long-run average of a random variable — each outcome weighted by how often it happens:

1E[X] = Σ value * probability

Task: write expected_value(values, probabilities) returning E[X], rounded to 4 decimal places.

  • The two lists line up by position: values[i] occurs with probability probabilities[i].
  • The probabilities are guaranteed to sum to 1.

Worth noticing that the expected value need not be an outcome you can ever observe. A fair die averages 3.5, a number that isn't on any face — it describes the distribution, not any single roll.

Examples

values = [1, 2, 3, 4, 5, 6]
probabilities = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6]
returns 3.5
values = [0, 100]
probabilities = [0.99, 0.01]
returns 1.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run