Theorem: A metric space $X$ is connected if and only if any continuous function $f:X\to \{0,1\}$ is constant.
Proof:Suppose $X$ is connected and $f:X\to \{0,1\}$ is continuous. If $f$ is not a constant function, then $f$ is onto. Let $A=f^{-1}(0)$ and $B=f^{-1}(1)$. Then $A\cup B=X$,and $A,B\neq \emptyset$. Also note that both are proper subsets of $X$ and are open and closed in $X$, a contradiction.
Suppose $X$ is not connected. Let $A$ and $B$ be the disconnection. Then define $f:X\to \{0,1\}$ such that $$f(x)=\begin{cases}
0, &\text{if $x\in A$}\\
1,&\text{if $x\in B$}
\end{cases}$$
$f$ is a non-constant continuous function(verify).
Another useful theorem is
A subset $I$ of $\Bbb{R}$ is connected if and only if $I$ is an
interval.
You can find a proof here.
I hope now you can complete your answer on your own.