Solution (source code)

= Solution

Assume $0<p<1$, so the ratio defining $Z_n$ is meaningful. Extend the <random walk> by $S_0=0$, the <filtration> by a trivial $\mathcal F_0$, and the process by $Z_0=1$. Write $r=q/p$. Each $Z_n=r^{S_n}$ is $\mathcal F_n$-measurable and integrable, since $|S_n|\leq n$. The next increment is independent of $\mathcal F_n$, so
$$
\mathbb E[Z_{n+1}\mid\mathcal F_n]
=Z_n\mathbb E[r^{X_{n+1}}]
=Z_n(pr+qr^{-1})
=Z_n(q+p)=Z_n.
$$
Therefore $\boxed{(Z_n)_{n\geq0}\text{ is a nonnegative martingale},\quad\mathbb EZ_n=1}$. This is the <exponential martingale of a biased simple random walk>, with exponent $\log(q/p)$. At $p=q=1/2$, it is the constant process one. The endpoint cases $p=0$ or $p=1$ require separate definitions and are not covered by the printed ratio.