Solution (source code)

= Solution

For $X$ with <binomial distribution> $B(n,p)$, where $n$ is a nonnegative <integer> and $0\leq p\leq1$, use its <probability mass function> and the <binomial theorem>:
$$
\begin{aligned}
M_X(t)&=\mathbb E[e^{tX}]
=\sum_{k=0}^n e^{tk}\binom nk p^k(1-p)^{n-k}\\
&=\sum_{k=0}^n\binom nk (pe^t)^k(1-p)^{n-k}
=\boxed{(1-p+pe^t)^n},\qquad t\in\mathbb R.
\end{aligned}
$$
This <moment-generating function of a binomial distribution> is finite for every real $t$, since the <random variable> has finite support. The formula also includes the degenerate cases $p=0$, $p=1$ and $n=0$.