Solution (source code)

= Solution

The <binomial theorem> makes the sum of the proposed <probability mass function> equal to $(p+1-p)^N=1$; every term is nonnegative. Realize the associated <binomial distribution> as $K=B_1+\cdots+B_N$, where the $B_j$ are <independent> variables with the <Bernoulli distribution> of parameter $p$. Each has <expected value> $p$ and <variance> $p(1-p)$. <Linearity of expectation> and <variance additivity for independent random variables> yield
$$
\boxed{\mathbb EK=Np,\qquad\operatorname{Var}K=Np(1-p).}
$$
At $p=0$ or $p=1$ this is a constant <random variable>; the same formulas apply, with the endpoint mass understood by continuity.