Bounded functions on subsets of Euclidean space

It is known that given any closed and bounded $X \subseteq \mathbb{R}^n$ and a bounded continuous function $f : X \to \mathbb{R}$, $f(X)$ has a minimum value and maximum value. This can be proved by noting that $X$ is compact and so its continuous image $f(X)$ is also compact.

However, if $f$ is continuous at all points in $X$ except for a finite number of singularities, does $f(X)$ still necessarily have a minimum value and maximum value?

-
Take $x\mapsto x^{-1}$ on $[-1,1]$! – albmiz-mth Feb 2 '13 at 13:31
Or $f(x)=x$, for $0<x<1$; $f(0)=f(1)=1/2$. – David Mitra Feb 2 '13 at 13:33
Sorry, I forgot to mention that $f$ has to be bounded as well! – Herng Yi Feb 2 '13 at 13:44

2 Answers

From David Mitra's comment, just take $f(x)=x$ for $0<x<1$ and define $f(0)=f(1)=1/2$. There is no maximum since for every $\varepsilon>0$, the set $(1-\varepsilon,1)\neq\varnothing$ and similarly for no minimum.

-

Let $f:[-1,1]$ be given by $f(-1)=f(1)=0$ and $f(x)=x$ otherwise. Then $f$ is bounded but has no maximum and has no minimum.

-
I forgot to add in the important detail that $f$ has to be bounded, but I've edited it into the question. – Herng Yi Feb 2 '13 at 13:42