Q:

Confused by apparently confusing question on limit...

Question: Let $f: R \rightarrow R$ be defined by
$$
f(x) = \begin{cases}
x & \text{if $x$ is an integer} \\[6px]
0 & \text{if $x$ is not an integer}
\end{cases}
$$
Find $\lim_{x \rightarrow 1} f(x)$.
My answer:
$\lim_{x \rightarrow 1^{-}}f(x)$ here we approach $f(x)$ from left and encounter fractions (decimals), $\{0.9,0.99,0.99,\dotsc\}$ so, the $\lim_{x \rightarrow 1^{-}}f(x)=0$
Similar logic for right hand limit and it also gives $0$. 
My confusion:
But, while calculating limit, is it not that we can simply put $x=1$ in to the appropriate function provided in the question?
So, $\lim_{x \rightarrow 1}f(x)$ here, can't we put $x=1$ and get the result of limit as $1$?
As in the following photo, we chose appropriate function and put $x=1$.

A:

My confusion: But, while calculating limit, is it not that we can simply put $=1$ in to the appropriate function provided in the question?

What you're asking is whether $\lim_{x\to a} f(x) = f(a)$ is always true.  The answer is no.  In fact, this exercise is designed to highlight that difference.  And you might consider why we would need limits at all if this were true.  
Your first answer, using the heuristic notion of evaluating $f$ at points closer and closer to $1$, but not equal to $1$, is the correct one.
It is true that $\lim_{x\to a} f(x) = f(a)$ for certain functions, the ones we call continuous functions.  Linear functions and polynomials are continuous functions.  That property is the one being invoked in the example photo you added.  But the original function you provided is not such a nice function, and is definitely not continuous.

