Show that $g $ is a continuous mapping Let $g $ be defined to equal $a _k $ on the closed sets $F _k $ , $0 \le k \le n $ , where the sets $F _k $ are disjoint subsets  of the real line and $a _k $ are real numbers.
Let $F = \cup_{k=1}^n F _k$
I want to show that $g $ is continuous on $F $.

I believe I can use the criterion of preimage of closed subsets being closed to show that $g $ is continuous. That is a preimage of  any closed set in the range of $g $ will be a finite union of the closed sets $F _k $ and thus closed. Thus $g $ is continuous.
Is this correct?
Thanks in advance!

Define $g : F \to \mathbb R$ by $g(x) = a_k$ if $x \in F_k$ for $0 \leq k \leq n$ where $F_k$ are disjoint and $F = \bigcup_{k = 1}^n F_k$. 
Let $K$ be a closed set in $\mathbb R$. Observe that $g^{-1}(K) = \bigcup_{k \in D} F_k$ where $D = \{k : g(F_k) = \{a_k\} \subseteq K \}$. Notice that $D$ has at most $n$ elements. Since $g^{-1}(K)$ is a finite union of closed sets, by definition of topology, it is closed. By definition of continuity (specifically the following definition : $g$ is continuous if $K$ closed implies $g^{-1}(K)$ is closed.), conclude that $g$ is continuous.
