Prob. 6, Sec. 18, in Munkres' TOPOLOGY, 2nd ed: A function $f \colon \mathbb{R} \to \mathbb{R}$ that is continuous at exactly one point Here is the definition of continuity given in Theorem 18.1 in Topology by James R. Munkres, 2nd edition: 

Let $X$ and $Y$ be topological spaces, let $p \in X$, and let $f \colon X \to Y$ be a function. Then $f$ is said to be continuous at point $p$ if, for every open set $V$ in $Y$ such that $f(p) \in V$, there is an open set $U$ in $X$ such that $p \in U$ and $f(U) \subset V$. 

Now here is Prob. 6, Sec. 18: 

Find a function $f \colon \mathbb{R} \to \mathbb{R}$ that is continuous at precisely one point. 

My Attempt: 

Let $f \colon \mathbb{R} \to \mathbb{R}$ be defined by 
  $$ f(x) = \begin{cases} 0 \ & \ \mbox{ if } \ x \in \mathbb{Q}, \\ x \ & \ \mbox{ if } \ x \in \mathbb{R} \setminus \mathbb{Q}. \end{cases} $$
First, let $p \colon= 0$. Then $p \in \mathbb{Q}$ of course, and so $f(p) = 0$. 
Let $\left( x_n \right)_{n \in \mathbb{N}}$ be any sequence of real numbers such that 
  $$ \lim_{ n \to \infty } x_n = p = 0. \tag{0} $$
  Then, for each $n \in \mathbb{N}$, we have
  $$ f \left( x_n \right) = \begin{cases} 0 \ & \ \mbox{ if } \ x_n \in \mathbb{Q}, \\ x_n \ & \ \mbox{ if } \ x_n \in \mathbb{R} \setminus \mathbb{Q}. \end{cases} $$
If $\left( x_n \right)_{n\in \mathbb{N}}$ has only finitely many rational terms, then there is a natural number $N$ such that $x_n \in \mathbb{R} \setminus \mathbb{Q}$ for all $n > N$, and so $f \left( x_n \right) = x_n$ for all $n > N$. Therefore, 
  $$ \lim_{n \to \infty} f \left( x_n \right) = \lim_{n \to \infty} x_n = 0 = f(p), $$
  by (0) above. 
If $\left( x_n \right)_{n \in \mathbb{N} }$ has only finitely many irrational terms, then there is a natural number $N$ such that $x_n \in \mathbb{Q}$ for all $n > N$, and so $f \left( x_n \right) = 0$ for all $n > N$. Therefore, 
  $$ \lim_{n \to \infty} f \left( x_n \right) = 0 = f(p). $$
Now suppose that $\left( x_n \right)_{n \in \mathbb{N} }$ has infinitely many rational terms and infinitely many irrational terms. Then there are strictly increasing functions $\phi \colon \mathbb{N} \to \mathbb{N}$ and 
  $\psi \colon \mathbb{N} \to \mathbb{N}$ such that 
  $$ \phi( \mathbb{N} ) \cap \psi ( \mathbb{N} ) = \emptyset, \qquad  \phi( \mathbb{N} ) \cup \psi ( \mathbb{N} ) = \mathbb{N},  \qquad  
x_{\phi(n)} \in \mathbb{Q}, \qquad x_{\psi(n)} \in \mathbb{R} \setminus \mathbb{Q}.  \tag{1} $$
  Then for each $n \in \mathbb{N}$, we have
  $$ f \left( x_{ \phi(n) }  \right) = 0, \qquad  f \left( x_{ \psi(n) }  \right) = x_{\psi(n)} .$$
  So 
  $$ \lim_{n \to \infty } f \left( x_{ \phi(n) }  \right) = 0, \qquad \lim_{n \to \infty } f \left( x_{ \psi(n) }  \right) = x_{\psi(n)}  = p = 0. \tag{2} $$
  Here we have used the fact that, since $\left( x_n \right)_{n \in \mathbb{N}}$ converges to $p$, therefore every subsequence of $\left( x_n \right)_{n \in \mathbb{N}}$ also converges to $p$. Moreover we have taken $p$ to be $0$ here. 
From (1) and (2) we can conclude that 
  $$ \lim_{n \to \infty} f \left( x_n \right) = 0 = f(0) = f(p), $$
  as required. 
Thus we have shown that the image sequence $\left( f \left( x_n \right)  \right)_{n \in \mathbb{N} }$ of every sequence $\left( x_n \right)_{n \in \mathbb{N} }$ that converges to $p = 0$ converges to $f(p) = 0$. So $f$ is continuous at $p = 0$. 
Next, suppose that $p \neq 0$. If $p$ is rational, then $f(p) = 0$. Let $\left( x_n \right)_{n \in \mathbb{N} }$ be a sequence of irrational numbers converging to $p$. Then 
  $$ \lim_{n \to \infty} f \left( x_n \right) = \lim_{n \to \infty } x_n = p \neq 0 = f(p).  $$ 
  On the other hand, if $p$ is irrational, then $f(p) = p \neq  0$. Let 
  $\left( x_n \right)_{n \in \mathbb{N} }$ be a sequence of rational numbers converging to $p$. Then 
  $$ \lim_{n \to \infty} f \left( x_n \right) = \lim_{n \to \infty } 0 = 0 \neq p = f(p).  $$ 
  Thus we have shown that $f$ cannot be continuous at any real  $p$ such that $p \neq 0$. 

Is what I have done so far correct? 
However, so far in Munkres, we do not have the sequential criterion for continuity at our disposal. So we must have recourse to the definition given above. 

Let $V$ be an open set in the range space $\mathbb{R}$ such that 
  $$0 = f(0) \in V.$$
  Then there is an open interval $(c, d)$ such that $$0 \in (c, d) \subset V. $$

Now what should be our open set $U$ in the domain space $\mathbb{R}$ such that $0 \in U$ and $f(U) \subset V$? 

Now suppose that $p \neq 0$. 
First, suppose $p$ is irrational. Then $f(p) = p \neq 0$, and there is an open interval $(a, b)$ such that $p \in (a, b)$ and $0 \not\in (a, b)$. Let us take $V \colon= (a, b)$. Then $V$ is open in the range space $\mathbb{R}$ and $f(p) \in V$. 
However, if $U$ is any open set in the domain space $\mathbb{R}$ such that $p \in U$, then there is an open interval $(c, d)$ such that $p \in (c, d) \subset U$. But 
  $$ f \left( \ (c, d) \ \right) = \left[ \ (c, d) \cap (\mathbb{R} \setminus \mathbb{Q} ) \ \right] \cup \left\{ \ 0 \ \right\} \not\subset V, $$
  because $0 \not\in V$. But as $(c, d) \subset U$, so $ f \left( \ (c, d) \ \right) \subset f(U)$. Therefore $f(U) \not\subset V$. 
Now suppose that $p$ is rational and $p \neq 0$. Then $f(p) = 0$. Let $V$ be the open interval $(-1, 1)$. Then $V$ is open in the range space $\mathbb{R}$, and $f(p) \in V$. 
However, if $U$ is any open set in the domain space $\mathbb{R}$ such that $p \in U$, then we can find an open interval $(a, b)$ such that $p \in (a, b) \subset U$ and such that $0 \not\in (a, b)$. 

What next? How to proceed from here? 
 A: Your proof, using sequences, of the fact that your function is continuous at $0$ is too complicated. There is no need whatsoever of dividing your sequences into several types. Just note that, for each $\varepsilon>0$, if you take $p\in\mathbb N$ such that $n\geqslant p\implies|x_n|<\varepsilon$ (such a $p$ exists because you are assuming that $\lim_{n\to\infty}x_n=0$), then $n\geqslant p\implies\bigl|f(x_n)\bigr|<\varepsilon$, since $f(x_n)=x_n$ or $f(x_n)=0$. So, $\lim_{n\to\infty}f(x_n)=0$.
If you want to prove that $f$ is continuous at $0$ using neighborhoods, you can do it. Let $V$ be a neighborhood of $0\bigl(=f(0)\bigr)$. Let $U=V$. Then $f(U)\subset V$. That's all.
And if you want to prove that $f$ is continuous only at $0$ using neighborhoods, you can do it too. Let $x\in\mathbb{R}\setminus\{0\}$. Let $\varepsilon>0$ be such that $0\notin(x-\varepsilon,x+\varepsilon)$. Then $(x-\varepsilon,x+\varepsilon)$ is a neighborhood of $x$. If $x\notin\mathbb Q$, then $(x-\varepsilon,x+\varepsilon)$ is a neighborhood of $f(x)$, but $f^{-1}\bigl((x-\varepsilon,x+\varepsilon)\bigr)=(x-\varepsilon,x+\varepsilon)\setminus\mathbb{Q}$, which is not a neighborhood of $x$. And if $x\in\mathbb Q$, then $(-\varepsilon,\varepsilon)$ is a neighborhood of $f(x)$, but $f^{-1}\bigl((-\varepsilon,\varepsilon)\bigr)=\mathbb{Q}\cup\bigl((-\varepsilon,\varepsilon)\setminus\mathbb{Q}\bigr)$, which, again, is not a neighborhood of $x$.
A: The function $f(x) =x\cdot \chi_{\mathbb{Q} } (x) $ where $$\chi_{\mathbb{Q}} (x) =\begin{cases} 1 \mbox{ if } x\in\mathbb{Q}\\ 0 \mbox{ if } x\in\mathbb{R}\setminus\mathbb{Q}\end{cases}.$$
Then $f$ is continuous only at the point zero.
