I am reading "Measure, Integration & Real Analysis" by Sheldon Axler.
The following exercise is Exercise 13 on p.38 in Exercises 2B in this book.
Exercise 13
Suppose $(X,\mathcal{S})$ is a measurable space, $E_1,\dots,E_n$ are disjoint subsets of $X$, and $c_1,\dots,c_n$ are distinct nonzero real numbers. Prove that $c_1\chi_{E_1}+\dots+c_n\chi_{E_n}$ is an $\mathcal{S}$-measurable function if and only if $E_1,\dots,E_n\in\mathcal{S}.$
My proof is here:
Suppose $E_1,\dots,E_n\in\mathcal{S}.$
Let $f:=c_1\chi_{E_1}+\dots+c_n\chi_{E_n}.$
Let $c_0:=0.$
Let $E_0:=X\setminus (E_1\cup\dots\cup E_n).$
Then, $E_0\in\mathcal{S}.$
Let $B$ be a subset of $\mathbb{R}.$
Let $I_B:=\{i\in\{0,1,\dots,n\}:c_i\in B\}.$
Then, $f^{-1}(B)=\bigcup_{i\in I_B} E_i\in\mathcal{S}.$
So, $f$ is an $\mathcal{S}$-measurable function.
Conversely, suppose $f$ is an $\mathcal{S}$-measurable function.
Let $i\in\{0,1,\dots,n\}.$
$\{c_i\}$ is a Borel set because $\{c_i\}$ is closed.
So, $E_i=f^{-1}(\{c_i\})\in\mathcal{S}.$
So, $E_1,\dots,E_n\in\mathcal{S}.$
I guess my proof is ok, but I fear situations where I think I am right but in reality I am wrong.
Is my proof ok?