A-noncompact, Does there always exist a continuous function $f: A \to \mathbb R$ which is bounded but does not assume extreme values? It's well known that if $ A \subset \mathbb R$ is compact then every continuous function $f:A \to \mathbb R$ is bounded and assume extreme values .So the obvious question is:

Given any non compact set $A \subset \mathbb R$ does there always exist a continuous function $f: A \to \mathbb R$ which is bounded but does not assume extreme values?

Any ideas for constructing such function?
Let $\langle X,d\rangle$ be any non-compact metric space, not necessarily a subspace of $\Bbb R$. Then $X$ is not countably compact, so $X$ has a countably infinite closed discrete subset $D=\{x_n:n\in\Bbb N\}$. Define
$$f:D\to\Bbb R:x_n\mapsto\begin{cases}
1-2^{-n},&amp;\text{if }n\text{ is even}\\
-1+2^{-n},&amp;\text{if }n\text{ is odd}\;.
\end{cases}$$
By the Tietze extension theorem there is a continuous $g:X\to[-1,1]$ such that $g\upharpoonright D=f$. Every metric space is perfectly normal, so $D$ is a zero set, and there is a continuous $\varphi:X\to[0,1]$ such that $\varphi(x)=0$ if and only if $x\in D$. Let $\psi:X\to[0,1]:x\mapsto 1-\varphi(x)$, and let
$$h:X\to\Bbb R:x\mapsto g(x)\psi(x)\;;$$
then $h$ is continuous, $\inf_{x\in X}h(x)=\inf_{x\in D}h(x)=-1$, $\sup_{x\in X}h(x)=\sup_{x\in D}h(x)=1$, and $h[X]\subseteq(-1,1)$, so $h$ attains neither its supremum nor its infimum.
Added: I’ve been asked to say something about how I thought of this construction. That’s a bit difficult, since the pieces were all just lying about in my head and came together without much effort on my part, but I’ll try. I know that countable compactness and compactness are equivalent for metric spaces, so I know right away that a non-compact metric space has a countably infinite closed discrete subset $D$. Because $D$ is discrete, any function from it to $\Bbb R$ will be continuous so I’ll begin by defining a bounded function from $D$ to $\Bbb R$ that doesn’t attain its supremum or infimum. There are may such; I chose to use the function $f$ above, but any other would have worked equally well.
This particular function $f$ takes values in $(-1,1)$ and has $-1$ and $1$ as its unattained extrema. If I can extend $f$ to a continuous $h:X\to(-1,1)$, I'll be done, so what do I know about extending continuous functions? Since $D$ is closed, the Tietze extension theorem applies, and it almost does what I want: it guarantees the existence of a continuous $g:X\to\Bbb R$ with the same extrema as $f$, which implies that $g[X]\subseteq[-1,1]$. Now I just have to make sure not to hit $-1$ or $1$. I can’t do that with $g$ itself, but if I can find a continuous function $\psi:X\to[0,1]$ that is $1$ only on $D$, the product $g\psi$ is guaranteed so map $X\setminus D$ into $(-1,1)$, and I’ll be home free. That requires that $D$ be a zero set in $X$, but I know that that’s true of every closed set in a metric space, so I’m done.
By the way, here’s an example to show that the result does not hold for arbitrary non-compact spaces. The ordinal space $\omega_1$ of all countable ordinals with the order topology is a standard example of a countably compact space that isn’t compact, so in particular it’s not metric. It happens that every continuous $f:\omega_1\to\Bbb R$ is eventually constant: there is an $\alpha_f&lt;\omega_1$ such that $f(\alpha)=f(\alpha_f)$ whenever $\alpha_f\le\alpha&lt;\omega_1$. The set $[0,\alpha_f]$ is a compact subset of $\omega_1$, so $f\upharpoonright[0,\alpha_f]$ attains its extrema, and $f(\alpha)=f(\alpha_f)$ for $\alpha\in\omega_1\setminus[0,\alpha_f]$, so $f$ has the same extrema as $f\upharpoonright[0,\alpha_f]$ and obviously attains them.
Let $A \subset \mathbb{R}$ be a noncompact set. Consider the function $f: A \to \mathbb{R}$ defined by $f(x) = \frac{1}{1+e^{-x}}$, the logistic function. Note that $f(x) \in (0,1)$ for all $x\in \mathbb{R}$ and therefore $f$ is bounded regardless of $A$. However, $f$ never assumes its extreme values on any noncompact set.