# $f(x)=x$ if $x$ is rational and $f(x)=1-x$ if $x$ is irrational

Show that $f$ assumes every value between $0$ and $1$ if

$$f(x) = \begin{cases} x, & x\ \text{is rational},\\ 1-x, & x\ \text{is irrational} \end{cases}$$

for all $x\in[0,1]$.

Is it enough to say that since the rationals and the irrationals are dense in the reals, every $x\in[0,1]$ will be assumed by $f$?

It's not sufficient, no. A set can be dense without containing every value, e.g. $\mathbb{Q} \cap [0,1]$.
The answer is much simpler. Take any $y \in [0,1]$. If $y$ is rational, then $f(y) = y$ is a value assumed by $f$. On the other hand, if $y$ is irrational, $1-y$ is irrational too, and $f(1-y) = 1-(1-y) = y$ is also a value assumed by $f$. So every element of $[0,1]$ is assumed by $f$.