LIVE·WAITING…
connecting to the live quote stream…
--:--:--UTC
#37
Expected value of a bet
easyMathsacceptance —~10 min
Implement expected_value(outcomes, stake) — the expected profit of a bet: outcomes is a list of [probability, payout] pairs (gross payout received in that outcome), stake is what you pay to play. Expected profit is Σ p·payout - stake.
Positive expected value is necessary and nowhere near sufficient — the next problem in the track, Kelly, is about how much of it you can afford to bet. Return the value rounded to 4 decimal places.
example 1
input
outcomes=[[0.5, 2.0], [0.5, 0.0]], stake=0.0
output
1
example 2
input
outcomes=[[0.5, 2.0], [0.5, 0.0]], stake=1.1
output
-0.1
note
A fair coin paying 2 for a 1.10 stake loses 0.10 a play.
constraints
- probabilities sum to 1
- stake ≥ 0
- 1 ≤ len(outcomes) ≤ 20
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to expected_value()
outcomes=[[0.5, 2.0], [0.5, 0.0]], stake=0.0
expected
1
the judge calls expected_value() with exactly these inputs · outputs are compared to 6 decimal places
● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice