TITLE: Prove that if $f: \mathbb{R} \to \mathbb{Q}$ is continuous then $f$ is constant
QUESTION [10 upvotes]: Suppose that  $f: \mathbb{R} \to \mathbb{R}$ is continuous and that $f(x) \in \mathbb{Q}$ for all $x \in \mathbb{R}$. Prove that f is constant.
I have the idea that because there is an irrational number between any two rational number then if the function is continuous, the function must be constant. But I don't know how to write out a proper proof for it.
Any help is appreciated. Thanks in advance.

REPLY [2 votes]: Contrary;Supposed $f$ is not constant, so without losing of general we suppose that $f$ has two value $x_{0},x_{1}\in Q$ such taht $x_{0}\neq‎x_{1}$, thus $\{x_{0}\}$ and $\{x_{1}\}$ make disconected for $f(R)$.This is contradiction,since $f(R)$ is conected