Showing $f$ is continuous on $M$ if $M=\bigcup_{n=1}^{\infty} U_n$ 
Let $f:(M,d)\to (N,\rho )$. If $M=\bigcup_{n=1}^{\infty} U_n$, where each $U_n$ is open, and if $f$ is continuous on each $U_n$, show that $f$ is continuous on $M$.

Attempt:
I note that $M=\bigcup_{n=1}^{\infty}U_n$. This means that $M$ is an open set because the infinite union of open sets is open. I am thinking that I will have to use the definition of continuity that states that preimages of open sets are open here. $M$ is open, so if I can show the preimage of $M$ is open, then I'm done. Perhaps I can use $f^{-1}(U)$, which should be an open set since $f$ is continuous on each $U_n$. 
However, I'm not sure where to start at this point. Any starting hints would be appreciated. Thanks.
 A: The whole space $M$ is open by definition and the inverse image of $M$ doesn't make sense, in general.
You can do both by showing that inverse images of open sets in $N$ are open in $M$, or showing continuity at each point of $M$.
If $V$ is open in $N$, then
\begin{align}
f^{\gets}(V)&=M\cap f^{\gets}(V)\\
&=\biggl(\bigcup_{i=1}^{\infty}U_n\biggr)\cap f^{\gets}(V)\\
&=\bigcup_{i=1}^{\infty}\bigl(U_n\cap f^{\gets}(V)\bigr)\\
\end{align}
Now, for each $n$, $U_n\cap f^{\gets}(V)=f_n^{\gets}(V)$, where $f_n$ is the restriction of $f$ to $U_n$. By hypothesis, this is open in $U_n$. But an open subset $U'$ of an open subset $U''$ of $M$ is open in $M$ (why?), so $f^{\gets}(V)$ is the union of open sets in $M$, hence it is open.
(Note: I like better $f^{\gets}$ instead of $f^{-1}$ for the inverse image.)
The “local” proof. Let $x\in M$; then $x\in U_n$, for some $n$. Since $f_n$ is continuous by hypothesis, for every neighborhood $V$ of $f_n(x)=f(x)$, there is an open neighborhood $W_x$ of $x$ in $U_n$ such that $f_n^{\to}(W_x)\subseteq V$. Again, $W_x$ is open in $U_n$, hence open in $M$.
Countability of the open cover is irrelevant, as it's clearly seen from the proofs. However the hypothesis of the $U_n$ being open is necessary.
A: You need to show the pre image of every open set is open. Note that if $V \subset N$ is open, $$f^{-1}(V) = \cup_{n=1}^\infty f^{-1}(V)\cap U_n.$$
A: The fact that the union is countable is in fact irrelevant. First note that when $f: M \rightarrow N$ is any function, and $f|A : A  \rightarrow N$ is any restriction of $f$ to a subset $A$ of $M$, that (for any $B \subset N$): $(f|A)^{-1}[B] = f^{-1}[B] \cap A$: a point $x$ is mapped under $f|A$ into $B$ iff it is mapped into $B$ by $f$ and $x$ is in $A$ (so that $f|A(x)$ actually is defined). 
Now $f|U_n$ is continuous by assumption, so we know that for all open $O \subset N$, $(f|U)^{-1}[O]$ is open in $U$, but this means that is open in $M$ as well (a set $A$ that is open in $U$ is by definition of the form $A' \cap U$, where $A' \subset M$ is open, and this is thus open as a finite intersection of open sets)!
Now, note that $f^{-1}[O] = \cup_n (f^{-1}[O] \cap U_n) = \cup_n (f|U_n)^{-1}[O]$, which is a union of open sets when $O$ is open in $N$. 
