Solution (source code)

= Solution

For a nonnegative integer-valued <random variable>, the <probability generating function> is
$$
G_X(s)=\mathbb E[s^X]=\sum_{j=0}^\infty P(X=j)s^j,
$$
with $0\leq s\leq1$ always allowed. Its derivative at $1$ from below gives the <expectation> when finite.

The waiting time $N$ has the positive-integer <geometric distribution> $P(N=j)=pq^{j-1}$. For the <capped geometric waiting time>, $X=j<k$ exactly when $N=j$, while $X=k$ occurs whenever $N\geq k$. Thus the terminal mass is $q^{k-1}$, giving
$$
\boxed{G_X(s)=p\sum_{j=1}^{k-1}q^{j-1}s^j+q^{k-1}s^k
=\frac{ps+q^ks^k(1-s)}{1-qs}}.
$$
The finite sum is a polynomial; any apparent singularity of the rational expression is removable. This includes $k=1$, where $G_X(s)=s$.

Differentiating the rational form at $s=1$ yields
$$
G_X'(1)=\frac{(p-q^k)p+pq}{p^2}=\boxed{\frac{1-q^k}{p}}.
$$
As a second interpretation, the <expectation> is the sum of the tail <probabilities> $P(X\geq j)=q^{j-1}$ for $1\leq j\leq k$. Their finite geometric sum gives the same answer.