Solution (source code)

= Solution

Take $X$ to be the set $\mathbb Q$, equipped with the <discrete metric>
$$
\boxed{d(p,q)=\begin{cases}0,&p=q,\\1,&p\ne q.\end{cases}\qquad f(p)=p\in\mathbb Q.}
$$
Every <Cauchy sequence> is eventually constant: its terms must eventually have mutual distance in this <metric> less than $1/2$. Consequently $X$ is a <complete metric space>. Its topology is the <discrete topology>, since every singleton is a ball of radius $1/2$ and every subset is a union of such balls.

For the codomain use the usual subspace topology on $\mathbb Q$. The inverse image of any <open set> there is a subset of the discrete $X$, hence is <open>. Therefore $f$ is <continuous> and plainly <surjective>. \b[A continuous image of a complete metric space need not be complete.] The two occurrences of $\mathbb Q$ have different domain and codomain metrics.