Let $X$ be a non empty topological space such that every function $f:X\rightarrow \mathbb R$ is continuous. Prove or disprove : $X$ has discrete topology.

I think the statement is true.

My attempt on proof:

If possible assume that $X$ does not have discrete topology. Then there is $A\subset X$ such that $A$ is not closed in $X$. Define $f$ as follows

$f:X\rightarrow \mathbb R$

$f(x)=1$ if $x \in A$ and $f(x)=0$ otherwise.

Then $f^{-1}({1})=A$ is not closed. Hence $f$ is not continuous which is a contradiction. So $X$ must have discrete topology. Am I right?

## Best Answer

This community wiki solution is intended to clear the question from the unanswered queue.

Your proof is correct as mentioned in the comments. However, you can do it easier with an argument sketched by Henno Brandsma. Note that $X$ is discrete iff all one-point sets $\{x\}$ are open. Now define $f(x) = 1$ and $f(y) = 0$ for $y \ne x$. Hence $\{x \} = f^{-1}((0,2))$ is open.