Real analysis: Continuity and discontinuity (Stephen Abbott. Understanding Analysis. pp 114 Question 1.3.6) The question reads

For the following choice of $A$, construct a function $f: \mathbb{R} \to \mathbb{R}$ that has discontinuities at every point $x$ in $A$ and is continuous on the complement of $A$.
  Let $A = \{ x \ :\ 0 < x < 1\}$.

My function is 
$$f(x) =
\begin{cases}
10 &\text{if $x \in (0,1)$ and rational,} \\
20 &\text{if $x \in (0,1)$ and irrational, and} \\
10 &\text{elsewhere.} \\
\end{cases}$$
By the way, this is a piecewise function.
Does this example work?
Also for $A = \{1/n: \text{$n \in \mathbb{N}$}\}$, does the function
$$f(n) =
\begin{cases}
1/n, &\text{if n is natural number, and} \\
0, &\text{elsewhere.} \\
\end{cases}$$
work?
 A: The second example you give does not work as written. Rather, define $f$ by saying that $f(x)=0$ unless $x=1/n$ for some $n$, in which case $f(x)=f(1/n)=1/n$. (I suspect this is actually what you meant to write.) This function is discontinuous at each $1/n$, having a jump discontinuity there. It is continuous at every other point: This is clear if the point is not $0$, since then there is a neighborhood around the point where $f$ is constantly zero. But $f$ is also continuous at $0$, since $f(1/n)=1/n\to0$. Formally: Given $\epsilon>0$, let $N$ be such that $1/N<\epsilon$. If $0<|x|<1/N$, then either $x$ is not a $1/n$, and $f(x)=0$, or $x=1/n$ for some $n$, which necessarily is strictly larger than $N$, so $f(x)=1/n<1/N<\epsilon$. In either case, $|f(x)-f(0)|<\epsilon$, so the definition of continuity at zero is satisfied.
Let's examine your first example. First of all, your function is discontinuous at each point $x$ of $[0,1]$ (including $0$ and $1$), since arbitrarily close to $x$ there are points $t$ with $f(t)=20$ and points $s$ with $f(s)=10$, so no matter whether $f(x)=10$ or $f(x)=20$, $f$ is discontinuous at $x$. Whether the example works, however, depends the precise meaning of "$f$ is continuous on the complement of $A$". If by this you mean that the restriction of $f$ to the complement of $A$ is continuous, then yes, the function you suggest is continuous there, since it is constant. On the other hand, the common meaning of the term is that $f$ is continuous at $x$ for any $x\notin A$. Under this common meaning, $f$ is continuous on $\mathbb R\setminus[0,1]$, since for each $x$ outside of $[0,1]$, there is a whole neighborhood where $ f$ is constant. On the other hand, $f$ is discontinuous at $0$ and at $1$, and neither point is in $A=(0,1)$.
The example cannot be fixed by changing the values of the constants. We actually need to change the definition a bit. One suggestion is to have $f(x)=10$ for $x$ outside of $(0,1)$, or inside $(0,1)$ and rational, and to define $f(x)$ for $x$ inside $(0,1)$ and irrational in a way that $f(x)$ approaches $10$ both at $0$ and $1$, and yet is discontinuous on $(0,1)$. I suggest you let $f(x)=20x+10$ for $x$ irrational and $0<x<1/2$, and $f(x)=30-20x$ for $x$ irrational and $1/2<x<1$. This is similar to your suggestion, but rather than having the function constant on the irrationals, I picked a value on the irrationals that is away from $10$ (so we still have discontinuity at every point of $(0,1)$, but approaches $10$ at both end-points (thus ensuring continuity at both $0$ and $1$).            
A: Yes, your example works. Let's verify, backwards.


*

*Is your function continuous on the complement of $(0,1)$? Yes, a constant function is continuous. EDIT: As brought up in the comments, you have to be careful at the points 0 and 1.

*Is your function discontinuous at every point in $(0,1)$? Well, can you find a point in the interval at which it is continuous? (The answer will be no).


For your second question, $f(n)$ does not meet the requirements for your conditions on the reals. If you are amending the question to work on $\mathbb{N}$, then you need to pick a metric.
A: Graph for $f(x)= \begin{cases} \color{green}{\text{ $20x+10$, $x$ irrational and $0<x<1/2$ }} \\ \color{magenta}{\text{ $30-20x$, $x$ irrational and } 1/2<x<1}  \end{cases}$

