The Lebesgue Covering Lemma 
Let $(X,\tau)$ a compact metric space and $\{ U_i : i \in I \}$ an open cover of $X$. Show that there is $r>0$ such that for all $a \in X$ there is an $i \in I$ such that $B_{r}(x) \subseteq U_{i}$.

My attempt:
By definition of compactness, $X$ is covered by some finite subset of $\{ U_{i} : i \in I \}$. Let $U_{1}, \ldots , U_{n}$ be such a finite subcover of $X$.
Choose any $x\in X$. Suppose $x$ lies in $U_1$. There is some number $r_{1}(x)$ such that for any $r < r_{1}(x)$, the ball $B_{r}(x)$ lies in $U_{1}$. For any $x \in X$, we may associate to $x$ the $n$ numbers $r_{1}(x), \ldots, r_{n}(x)$, noting that at least one of these is non-negative. Let $r(x)$ be the least non-negative member of $\{ r_{1}(x), \ldots , r_{n}(x) \}$.
Below, I prove that $r: X \to \mathbb{R}$ is a continuous function. As $r$ is continuous, $r(X)$ is a continuous subset of the real numbers. Therefore $r(X)$ is a finite union of finite closed intervals in $\mathbb{R}$. In particular, $r(X)$ contains a least element which we denote by $r_{0}$. Note that as $r(x)$ is greater than zero for all $x \in X$, we know that $r_{0} > 0$. For any $p<r_{0}$ and for any $x\in X$, we know that $B_{p}(x)$ lies in at least one $U_{i}$.

Is this correct? Can you give me another alternative solution?
 A: The argument does not work as it stands: your numbers $r_i(x)$ are not well-defined, so you’ve no guarantee that $r$ is continuous. Moreover, there’s nothing to keep you from choosing each $r_i$ to be $0$, since $B_0(x)=\varnothing\subseteq U_i$, and in that case $\{r_1(x),\dots,r_n(x)\}$ has no non-negative member. If you use this approach, you need to choose the $r_i(x)$ more systematically, and in a way that ensures that you choose a positive value if possible. One way is to let $r_i(x)$ measure the distance from $x$ to $X\setminus U_i$, as I now see that Arthur Fischer has just suggested, so I’ll say no more about that approach.
Here’s a completely different approach. Let $\mathscr{U}$ be an open cover of $X$. For each $x\in X$ there is an $\epsilon(x)$ such that $B_{\epsilon(x)}(x)\subseteq U$ for some $U\in\mathscr{U}$. Let $\mathscr{B}=\{B_{\epsilon(x)/2}(x):x\in X\}$; this is an open cover of $X$, so it has a finite subcover $\{B_{\epsilon(x_1)/2}(x_1),\dots,B_{\epsilon(x_n)/2}(x_n)\}$. Let $\epsilon=\frac12\min\{\epsilon(x_1),\dots,\epsilon(x_n)\}$.
Let $x\in X$ be arbitrary; $x\in B_{\epsilon(x_k)/2}(x_k)$ for some $k\in\{1,\dots,n\}$. Suppose that $y\in B_\epsilon(x)$, then $d(y,x_k)\le d(y,x)+d(x,x_k)<\epsilon+\epsilon(x_k)/2\le 2\epsilon(x_k)/2=\epsilon(x_k)$, so $y\in B_{\epsilon(x_k)}$, and therefore $B_\epsilon(x)\subseteq B_{\epsilon(x_k)}$. Thus, for each $x\in X$ the set $B_\epsilon(x)$ is a subset of some member of $\mathscr{U}$.
A: You are pretty close.  The main problem seems to be the ad hoc nature of your $r_i (x)$, which would preclude ever being able to prove the continuity of $r$.  Instead, once you have your finite subcover $U_1 , \ldots , U_n$, for each $i \leq n$ define a function $f_i : X \to \mathbb{R}$ by
$$f_i (x) = d ( x , X \setminus U_i ) = \inf \{ d(x,y) : y \in X \setminus U_i \}.$$
Show that these functions are continuous, and $f_i (x) > 0$ iff $x \in U_i$.
Next consider the function $f : X \to \mathbb{R}$ defined by $$f(x) = \max \{ f_1 (x) , \ldots , f_n (x) \}.$$
The compactness of $X$ will tell you something important about this continuous function, and this something important should lead you to finding $r$.
A: By choosing a finite subcover $(U_i)_{1\leq i\leq N}$ right at the start one looses a lot of manoeuvrability. Here is another approach: Define the function $\rho: X\to{\mathbb R}_{>0}$ by
$$\rho(x)\ =\ \sup\{\delta>0\ |\ \exists i\in I:\ U_\delta(x)\subset U_i\}\qquad(x\in X)\ .$$
So any ball with center $x$ and radius $\rho'<\rho(x)$ is contained in at least one $U_i$. By means of the triangle inequality one easily shows that the function $\rho$ is $1$-Lipschitz, whence continuous on $X$. As $\rho(x)>0$ for all $x$ there is a $\rho_{\min}>0$ with $\rho(x)\geq \rho_{\min}$ for all $x$. Now put $r:=\rho_{\min}/2$.
