The following is not a homework problem. I am doing it for self study.
Prove that any continuous function from $\mathbb{R}$ to $\mathbb{Q}$ is constant.
Here is my proof:
Let $f:\mathbb{R}\rightarrow \mathbb{Q}$ be such a function.
? We first show that $\mathbb{Q}$ is disconnected. Let $p$ be an irrational number. Then we can write $\mathbb{Q}$ as $$ \big( \mathbb{Q} \cap (-\infty,p) \big) \cup \big( \mathbb{Q} \cap (p,\infty) \big), $$ which is a disconnection of $\mathbb{Q}$.
Moreover, $\mathbb{Q}$ is also totally disconnected, as any open subset $U$ of $\mathbb{Q}$ must contain two rational numbers and there is always an irrational number between the two, and we can use that rational number to create a disconnection. Therefore the only connected subsets of $\mathbb{Q}$ are the singleton sets $\{q\}$, where $q \in \mathbb{Q}$, which are closed.
We will show that $f(\mathbb{R})$ must be connected. Assume not, then $$ f(\mathbb{R})= U\cup V, $$ where $U$ and $V$ are nonempty open subsets of $\mathbb{Q}$ such that $$ U \cap V= \emptyset .$$ This implies $$ \mathbb{R} = f^{-1} \big( U \cup V \big) = f^{-1}(U)\cup f^{-1}(V), $$ where $f^{-1}(U),f^{-1}(V)$ are nonempty, nonintersecting subsets of $\mathbb{R}$. This, however, is a contradiction, as $\mathbb{R}$ is connected. Therefore no such set $U$ and $V$ can exist.
As we have already shown, the only connected subsets of $\mathbb{Q}$ are the singleton sets $\{q\}$, so $f(\mathbb{R})$ must be such a set.
Something about this does not seem quite satisfactory, as if I am missing something. Could anyone tell me a flaw in my logic? Also, is there a more satisfactory way to prove this theorem?