
  Let $X$ be a compact metric space, show that a continuous function $f:X\rightarrow\mathbb{R}$ attains a maximum and a minimum value on $X$.   


Attempt: So the important thing is that I have previously shown that such a function is bounded and that for compact $X$, $f(X)$ is compact given $f$ continuous. In $\mathbb{R}$, compact $\implies$ closed and bounded. So $f(X)$ is closed and contains its accumulation points, and it is bounded so $\exists \sup(A),\inf(A)$ and since closed $\implies \sup(A)\in A, \inf(A)\in A$. 

Did I miss anything/make an unwarranted leap of logic?

Here’s an example of how the same argument could be written up nicely.


  Since $X$ is compact and $f$ is continuous, $f[X]$ is a compact subset of $\mathbb{R}$ and therefore closed and bounded. Since $f[X]$ is bounded, it has both a supremum and an infimum, and since it is closed, $\sup f[X]\in f[X]$ and $\inf f[X]\in f[X]$. Thus, there are $x_0,x_1\in X$ such that $f(x_0)=\inf f[X]$ and $f(x_1)=\sup f[X]$; that is, $f$ attains its minimum and maximum values at $x_0$ and $x_1$, respectively.

