Shouldn't this function be discontinuous everywhere? I was thinking about single point continuity and came across this function. $$
f(x) = \left\{
        \begin{array}{ll}
            x & \quad x\in \mathbb{Q}\\
            2-x &  \quad x\notin \mathbb{Q}
        \end{array}
    \right.
$$ We know this function is continuous only at $x=1$ . But doesn't that contradict our whole idea of continuity? A function is continuous if we are able to draw the function without lifting our pen or pencil. But here both the pieces of the function exist at specific places, so we have to lift our pen. Shouldn't the function be discontinuous everywhere? Looks like a stupid doubt though.
 A: The idea that "a function is continuous if (and only if) its graph can be drawn without lifting one's pen(cil)" is sometimes adequate for communicating with non-mathematicians, but is technically flawed for multiple reasons.
For convenience, let's call this "condition" pen continuity.
First, as other answers note, a function must be continuous on an interval to have any hope of being pen continuous. Unfortunately for "pen continuity", there are a couple of reasons a function might be continuous (to a mathematician, using the $\varepsilon$-$\delta$ definition), but not continuous on an interval:


*

*A function can be continuous at a single point (such as the function in your post), or at each point of a complicated set that contains no interval of real numbers (such as Thomae's function, which is continuous at $x$ if and only if $x$ is irrational).

*A function can be continuous at every point of its domain, but the domain is not an interval (and perhaps contains no interval). Think, for example, of 
Przemysław Scherwentke's example $f(x) = 1/x$ for $x \neq 0$, which is continuous throughout its domain (the set of non-zero real numbers), or of the zero function defined on an arbitrary set of real numbers (which can be nastier than the human mind can comprehend).
So, let's focus on (real-valued) functions that are continuous at every point of an interval. Depending on your definition of a pen, not every continuous function is pen continuous (!). If a "pen" is a mathematical point, and "draw" has its ordinary meaning ("the pen can be traced along the graph in finite time", say), then most continuous functions are not pen continuous, because their graphs have infinite length over arbitrary subintervals (or "are not locally rectifiable", in technical terms). (The Koch snowflake curve isn't a graph, but may be a familiar non-rectifiable example.)
To emphasize, a "typical" continuous function is nowhere-differentiable: Its graph looks something like an EKG or a seismograph tracing or the curves you draw after drinking 50 cups of espresso. "Zooming in" only reveals details at smaller and smaller scales, peaks and valleys whose total length (over an arbitrarily short subinterval of the domain) may well be infinite. Only functions of bounded variation have graphs of finite length, and that's a "thin" subset of all continuous functions.
[If instead you want to think of "real" pens, whose tip has positive radius, you arrive at mathematically interesting territory, including Hausdorff measure and geometric measure theory.]
The bottom line (literally!) is, a mathematician mustn't conflate "continuity" with "pen continuity".
A: A function is continous at a point $a$ if:
$$\lim_{x \to a}f(x)=f(a)$$
For your function, (except one point) no matter what point you choose there are irrational numbers alongside rational numbers so you can't find such a limit. The exception is a point that two conditions yield the same value, i.e., their intersection. Since, the intersection point ($2-x=x$) is $x=1$, both conditions tend to go to $1$ and above limit exists. Therefore it is only continuous at that point. 
A: More precisely, a function is continuous over an interval if we are able to draw the function without lifting our pen or pencil within that interval, in our intuition. This function is only continuous at one point.
A: No, mathemathic hasn't failed. You has.
Drawing the graph of function without lifting pencil is only the initial intuition. Consider $f(x)=1/x$, which is continuous.
A: user86418 gave some examples of where pen-continuity differs from continuity. Here are two more important distinctions. With a pen, you can only draw curves that have finite length and bounded derivative, otherwise you need infinite ink and either infinite time or infinite speed. But there are plenty of continuous curves that have infinite length.
Many fractals, which are beautiful (at least to some) continuous curves, have infinite length, such as the Koch snowflake, Sierpinski curve, Moore curve and Takagi_curve.
There are also 'simpler' examples. $\left( x \mapsto x \sin(\frac{π}{x^2}) \right)$ is continuous but has infinite length on any interval containing $0$, because the arc length between consecutive roots $\frac{1}{\sqrt{n}},\frac{1}{\sqrt{n+1}}$ is at least $\frac{2}{\sqrt{n+1}}$, and $\sum_{n=1}^\infty \frac{2}{\sqrt{n+1}} = \infty$. This example also has unbounded derivative, which means that you have to keep changing direction at higher and higher speed if you every want to finish drawing it!
