Exercises#

Tests sphinx-exercise directives: exercise, exercise-start/-end, and solution-start/-end (the form used heavily in QuantEcon lectures).

Plain exercise#

Exercise 1

Prove that for any two events \(A\) and \(B\), \(\Pr(A \cup B) = \Pr(A) + \Pr(B) - \Pr(A \cap B)\).

Exercise with multi-paragraph content#

Exercise 2

Consider a sequence of independent coin flips, each with probability \(p\) of landing heads.

Let \(X\) be the number of heads in the first \(n\) flips. Show that \(X \sim \text{Binomial}(n, p)\) and compute its mean and variance.

State your assumptions clearly.

Exercise with code-block prompt#

Exercise 3

Write a Python function that computes the sample mean and sample variance of a list of floats in a single pass, using Welford’s algorithm.

The signature should be:

def welford(xs: list[float]) -> tuple[float, float]:
    ...

Exercise + solution pair (start/end form)#

Exercise 4

Compute \(\sum_{k=1}^{n} k = ?\) in closed form.

Multiple exercises in sequence#

Exercise 5

First exercise in the sequence.

Exercise 6

Second exercise in the sequence.

Exercise 7

Third exercise in the sequence. Vertical spacing between consecutive exercise blocks should remain consistent.