Prove that a subset $E$ of a metric space $X$ is open if and only if there exists a continuous function $f\colon X\to \mathbb{R}$ such that $E=\{x\in X\mid f(x)\gt 0\}$.
I would appreciate guidance on how to structure this proof, as well as any general insights about why this result holds.
What I've Tried: Direction 1 (If such an $f$ exists, show $E$ is open): Here, I understand that if $f$ is continuous, then $E=\{x∈X:f(x)>0\}$ should be open because it’s the preimage of $(0,\infty)$, which is open in $\mathbb{R}$. However, I’d like to confirm if this reasoning is sufficient. I am also stuck regarding direction 2.