Solution (source code)

= Solution

For known $\lambda_0$, the likelihood ratio of $\pi=1/2$ to $\pi=0$ is
$$
\Lambda=2^{-n}(1+e^{\lambda_0})^{n_0},
$$
which increases with $n_0$. Reject for $n_0>c$, with randomization at $n_0=c$ chosen so that the null rejection probability is exactly $\alpha$. Since the zero indicators form a Bernoulli family with success probability increasing in $\pi$ and have a monotone likelihood ratio in $n_0$, the <Karlin-Rubin theorem> makes this test uniformly most powerful for $\pi>0$.