TITLE: Continuous map and irrational numbers
QUESTION [7 upvotes]: My question is the following :

Let $f:\mathbb{R}\to\mathbb{R}$ be a continuous map such as each irrational number is mapped to a rational number (i.e. $f(\mathbb{R}\backslash\mathbb{Q})\subset\mathbb{Q}$). Show that $f$ is a constant map.

What I have done :
Let's suppose that $f$ is not a constant map, i.e. it exists $x,y\in\mathbb{R}$ such that $f(x)\neq f(y).$ As $f$ is continuous, the intermediate value theorem gives us that $[f(x),f(y)]\subset f([x,y]).$ But, as $$f([x,y])\subset f(\mathbb{R})=f(\mathbb{R}\backslash\mathbb{Q}\,\cup\,\mathbb{Q})=f(\mathbb{R}\backslash\mathbb{Q})\,\cup\,\bigcup_{n\in\mathbb{N}}\{f(p_n)\}\subset\mathbb{Q}\,\cup\,\bigcup_{n\in\mathbb{N}}\{f(p_n)\},$$ where $p_n$ is a sequence which describes $\mathbb{Q},$ we would get that $[f(x),f(y)]$ is a subset of a countable set and so is countable, which is a contradiction and so $f$ is constant.
My questions :
Is my proof correct, and if yes, does someone see an other way to answer it ?
Thank you for your comments, and happy new year !

REPLY [6 votes]: Looks good! As a side note, as you asked for alternative methods, you do not have to formulate the proof by contradiction. Note that the image of $f$ is 
$$
f(\mathbb{R})=f(\mathbb{R}\setminus\mathbb{Q}\cup\mathbb{Q})=f(\mathbb{R}\setminus\mathbb{Q})\cup f(\mathbb{Q})=A\cup \{f(q_n):n\geq1\}
$$
Where $A\subset \mathbb{Q}$ and $q_n$ is an enumeration of the rationals. Thus $f(\mathbb{R})$ is countable, and a continuous map with a countable image is constant.