Converse of intermediate value theorem

Statement
Suppose $$X$$ is a topological space that satisfies the conclusion of the intermediate value theorem: For any continuous function $$f:X \to \R$$, and two elements $$x_1,x_2 \in X$$ such that $$f(x_1) < f(x_2)$$, $$f(X)$$ must contain $$[f(x_1),f(x_2)]$$.

Then, $$X$$ is a connected space.

Converse

 * Intermediate value theorem

Proof
Given: A topological space $$X$$ such that for any continuous function $$f:X \to \R$$, and two elements $$x_1,x_2 \in X$$ such that $$f(x_1) < f(x_2)$$, $$f(X)$$ must contain $$[f(x_1),f(x_2)]$$.

To prove: $$X$$ is connected.

Proof: Suppose not, i.e., suppose $$X$$ is not connected. Then, $$X$$ is a union of two nonempty disjoint open subsets $$U$$ and $$V$$. Consider the function $$f:X \to \R$$ defined by $$f(x) = 0 \ \forall \ x \in U$$ and $$f(x) = 1 \ \forall \ x \in V$$. This is a continuous function (in fact, all its fibers are open).

Pick $$x_1 \in U$$ and $$x_2 \in V$$. By our construction, $$f(x_1) < f(x_2)$$, so by the given data, $$f(X)$$ should contain the interval $$[f(x_1),f(x_2)] = [0,1]$$. But this contradicts the fact that the image of $$f$$ is the two-element set $$\{ 0, 1 \}$$.

Thus, our original assumption that $$X$$ is not connected cannot hold. Hence, $$X$$ must be connected.