Show that there exists a real function of the real variable that takes any real value on any interval 
Show that there exists a functon $f:\mathbb R\to\mathbb R$ such that if
  $I$ is any nonempty open interval then $f(I)=\mathbb R$.

For now I do not see how to approach this exercise. Would you have a hint ?
Note it is for any interval.
 A: You may use a Hamel basis (as an alternative, to the answer by David C. Ullrich already posted). A Hamel basis is a basis of the reals $\mathbb R$ as a vector space over the rationals $\mathbb Q$. Let $\mathcal B=\{I_n:n\in\mathbb N\}$ be the family of all open intervals with rational endpoints, indexed by the set $\mathbb N$ of positive integers. Any Hamel basis must contain a subset $H$ with all of the following properties: (a) $H$ has cardinality continuum (same as the cardinality of the real line), (b) $H$ is bounded, and (c) every (finite) linear combination of (different) elements of $H$ with non-zero rational coefficients results in irrational numbers only. 
(Just use that any Hamel basis $A$ must have cardinality continuum, and throw away the finitely many elements of the basis that appear in the linear combination representing the number $1$, and use that there must be an $n$ such that $A\cap[-n,n]$ must have cardinality continuum since the continuum has uncountable cofinality ... well alternatively use that $[0,1]$ spans the reals over the rationals, and hence contains a Hamel basis, from which we could throw out the finitely many elements that appear in the linear combination representing $1$, and obtain our $H$ satisfying the above conditions (a), (b), and (c). It is not too difficult to show that every Hamel basis must have the cardinality of the continuum, I could expand on that if necessary.) 
Next pick a strictly decreasing sequence of positive rationals $p_n$ and a sequence of rationals $q_n$ such that $K_n\subset I_n$, where 
$K_n=p_n H + q_n := \{p_n h + q_n: h\in H\}$. Note that if $n\not=m$ then $K_n\cap K_m=\emptyset$, indeed, if $p_n h + q_n=p_m g + q_m$ for some $h,g\in H$, then $p_nh-p_mg= q_m-q_n$, but the left-hand side is irrational (by property (c) when $h\not= g$, and by $p_n\not=p_m$, when $h=g$), while the right-hand side is rational. 
Take any surjective function $\varphi:H\to\mathbb R$. If $x$ is any real number of the form $p_n h + q_n$ for some $n\in\mathbb N$ and some $h\in H$ define $f(x)=\varphi(h)$. (Note that such a representation of $x$, if it exists, is unique, and hence $f$ is well-defined.) If $y$ is a real number which is not of the above form (for any $n\in\mathbb N$ and any $h\in H$) then define $f(y)$ arbitrary. (Finally, if $I$ is any open interval, then $I_n\subset I$ for some $n$, hence $f(I)\supset f(I_n)\supset f(K_n)=\mathbb R$.)   
A: Here's a solution to an analogous problem; it seems likely that it could be converted to a solution to the problem you pose, the details might be messy.
Let $K=\{0,1\}^{\mathbb N}$, the set of all sequences of $0$'s and $1$'s.
If $F$ is a finite sequence of $0$'s and $1$'s, let $I_F\subset K$ be the set of all sequences that start with $F$. (So for example if $s=(0,1,0,1,\dots)$ then $s\in I_{(0,1,0)}$ and $s\notin I_{(1)}$.)
We show that 


There exists $f:K\to K$ such that $f(I_F)=K$ for every finite sequence $F$.


First define $a:K\to\{0,1\}$ by saying $a(s)=1$ if and only if $$\limsup\frac1n(s_1+\dots+s_n)>1/2.$$
Note that if $s=s'$ except for finitely many terms then $a(s)=a(s')$.
If $A\subset\mathbb N$ is infinite and $s\in K$ let $s_A\in K$ be the sequence that might be loosely described as the restriction of $s$ to $A$. For example if $A=\{2,4,6,\dots\}$ then $$s_A=(s_2,s_4,\dots).$$
Now choose disjoint infinite sets $A_1,A_2,\dots\subset\mathbb N$ and define $f:K\to K$ by $$f(s)=(a(s_{A_1}),a(s_{A_2}),\dots).$$
It's clear that $f(K)=K$, and since finitely many terms don't matter to $a(s)$ it follows that $f(I_F)=K$.
In case the connection to the question you asked is not clear: Define $b:K\to\mathbb R$ by $$b(s)=\sum_{j=1}^\infty s_j2^{-j}.$$
Then $b$ is not a bijection from $K$ to $[0,1]$, but it's "almost" such a bijection (the details here are what I fear might be messy). Note that if $F$ is a finite sequence then $b(I_F)$ is a dyadic subinterval of $[0,1]$ (and of course also note that any open interval contains a dyadic subinterval).
I think it's now clear that one can construct the function you ask for by diddling with binary expansions.
A: This question has been answered, it's a duplicate, and at hindsight my answer here (the older one, as I am posting a second answer to the same question now) has a lot in common with the (even older) answer by zhw. User zhw used Cantor sets, and I used a Hamel basis, but I thought I would present a different construction, again recursive, but of a somewhat different type, and using only a cardinality argument, instead of any special sets of reals. 
Let $\mathcal B=\{I_n:n\in\mathbb N\}$ be the family of all open intervals with rational endpoints (as in zhw's answer as well as in my previous answer). This time, list $\mathbb R=\{x_\alpha:\alpha<\frak c\}$, where $\frak c=2^{\aleph_0}$ is the cardinality of the continuum. Recursively, for each $\alpha$ pick a countable dense set $D_\alpha=\{z_{\alpha,n}:n\in\mathbb N\}$ (where $\mathbb N$ is the non-negative integers) such that $z_{\alpha,n}\in I_n$ and $D_\alpha\cap D_\beta=\emptyset$ if $\beta<\alpha<\frak c$. This could be done since if $0<\alpha<\frak c$ then 
the cardinality $|I_n|=\frak c$ but $|\cup_{\beta<\alpha}D_\beta|\le 
|\alpha|\cdot\aleph_0=\max\{|\alpha|,\aleph_0\}<\frak c,$ so we could pick 
$z_{\alpha,n}\in I_n\setminus\cup_{\beta<\alpha}D_\beta\,.$ For each $\alpha$ and each $n$ define $f(z_{\alpha,n})=x_\alpha$, that is $f(D_\alpha)=\{x_\alpha\}$ (the function $f$ takes constant value $x_\alpha$ on the set $D_\alpha$). If $y\in\mathbb R\setminus\cup_{\alpha<\frak c}D_\alpha$ define $f(y)$ arbitrarily. (Note that $f$ is well-defined since if $\beta<\alpha$ then $z_{\alpha,n}\not=z_{\beta,m}$, for all $m,n\in\mathbb N$.) Then for each $n$ we have $f(I_n)=\mathbb R$ since for each $\alpha$, by construction $x_\alpha =f(z_{\alpha,n})$ and $z_{\alpha,n}\in I_n\,.$ 
