Is a rational-valued continuous function $f\colon[0,1]\to\mathbb{R}$ constant? Let $f\colon[0,1]\to\mathbb{R}$ be continuous such that $f(x)\in\mathbb{Q}$ for any $x\in[0,1]$. Intuitively I feel that $f$ is constant, since $\mathbb{Q}$ is dense in $\mathbb{R}$.
How can I formally write this down?
 A: Hint: Use the intermediate value theorem
A: From an advanced standpoint, you know that $\mathbb{R}$ is connected.  We know that $\mathbb{Q}$'s connected components are all singleton points.  Since the image of the real line under any continuous function is connected, its image must be a point. Therefore it is constant.
A: Suppose $f$ isn't constant. Then for some $a,b\in[0,1],$ $f(a)\neq f(b);$ WLOG $f(a)<f(b)$.
Since $f$ is continuous, by the Intermediate Value Theorem, it must take every value in the interval $[f(a),f(b)]$. But this interval contains an irrational number (in fact, uncountably many of them). Contradiction.
This doesn't quite follow fron the fact that $\mathbb{Q}$ is dense in $\mathbb{R}$; it follows more from the density of the irrational numbers, the complement of $\mathbb{Q}$.
A: Suppose $\alpha \notin \mathbb{Q}$. Let $A_\alpha = f^{-1} (-\infty, \alpha)$, $B_\alpha = f^{-1} (\alpha, \infty)$. Since $f$ is continuous, $A_\alpha,B_\alpha$ are open
Since $\alpha \notin f [0,1]$, we see that $[0,1] \subset A_\alpha \cup B_\alpha$, and since $[0,1]$ is connected, we must have $[0,1] \subset A_\alpha$ or $[0,1] \subset B_\alpha$.
Now suppose $f$ is not constant, then we have $q_1,q_2 \in f[0,1]$ for two rationals $q_1 < q_2$. Pick $\alpha \in (q_1,q_2) \setminus \mathbb{Q}$. Then, as above, we have $[0,1] \subset A_\alpha$ or $[0,1] \subset B_\alpha$. The first case implies $q_2 < \alpha$, the second case implies $q_1 > \alpha$, which is a contradiction. Hence $f$ is a constant.
The proof relies on three things, the continuity of $f$, the connectedness on $[0,1]$ and the fact that between any two distinct rationals there is an irrational.
A: by ways of contradiction 
 assume $f$ is not constant .
$f$ is continuous on a closed and bounded interval then $f$ has absolute max and min .i.e.$\exists$ $x_0,y_0 \in [0,1]$ such that $f(x_0)\le f(x) \le f(y_0)$ $\forall x \in [0,1]$
from assumption $f(x_0)\ne f(y_0)$  and  $f(x_0),f(y_0)$ are rational value (from question)
by density theorem $\exists$ $r \in Q' $  such that $f(x_0)<r<f(y_0)$
then by intermediate value theorem  $\exists c \in [0,1]$ such that $f(c)=r$ 
which contradicts with f has only rational value
therefore $f$ is constant. 
