Show that $I$ is an interval iff any function $f:I\rightarrow \{0,1\}$ is continuous. Let $I\in R$ be a nonemplty set. Show that $I$ is an interval iff any function $f:I\rightarrow \{0,1\}$ is continuous.
I've no idea how to handle this problem. Thanks in advvance to anyone who comes up with a step - solution.

Can't be true.
Let $I$ be any set, interval or not, then $f(x) = 0$ is a continuous function whether or not $I$ is an interval.  And $I$ = $A\cup B$ where $A$ and $B$ are separated then if $f(A) = 0$ and $f(B) = 1$, $f$ is continuous.
Likewise on an interval one can easily find an non-continuous function to $\{0,1\}$.  Simply map any arbitrary points to $0$ and all the rest to $1$.  Say, $I = [0,1]; f(1) = 1;f(x) = 0$ if $x<1$ .
As egreg puts in the comments, a true statement would be $I$ is an interval if and only if every continuous function $f:I\rightarrow \{0,1\}$ is constant.
Proof. (I'm going to use notation $<a,b>$ to be an interval without distinguishing whether is open, closed or clopen.)
If $I= <a,b>$ is an interval and $f:I \rightarrow \{0,1\}$ be a continuous  function. Note: for any $x,y \in R$ that $|f(x) - f(y)|$ is either $0$ or $1$.  There is no other option.
Let $m = \frac {a+b}2 \in I$.  $x$ is the mid point of $I$.  Let $f(m) = k$.  Let $K = \{x \in [<a,m]| f(x) \ne f(m)\}$.  If $K$ is non-empty, let $d = \sup K$.  Then for every neighbor of $d$ you will have a $y \le d: y \in K$ and a $w > d: w\not \in K$ so $f(y)\ne f(w)$ and $|f(y) - f(w)| = 1$ which contradicts that $f$ is continuous.  (Continuity says for $\epsilon > 0$ there is a neighborhood, $N$, of $d$ where $x,y \in N$ then $|f(x) - f(y)| <\epsilon$ which is not the case for $\epsilon \le 1$.)
So $K$ is empty.  So $f$ is constant when restricted to $<a,m]$.
A similar argument shows $f$ is constant when restricted to $[m, b>$.  So $f$ is constant on $<a,b> = I$.  
If $I$ is not an interval and $I$ has two or more points, then there exists an $m \not \in I$ so that there is an $a < m$ with $a \in I$ and a $b > m$ with $b \in I$.  Let $f(x) = 0$ for all $x \in I$ where $x < m$ and let $f(x) = 1$ for all $x \in I$ where $x > m$.  This function is continuous and non-constant.
... because ... for any $x \in I$ and any $\epsilon > 0$.  Let $\delta = |x-m|$.  If $y \in I$ and $|x - y| < \delta$ then either $x,y$ are both less than $m$ or $x,y$ are both greater then $m$.  Either way, then $f(x) = f(y)$ and $|f(x)-f(y)| = 0 < \epsilon$.
Hmmm.... if $I$ has one point or $I$ is empty, then all functions from $I$ to $\{0,1\}$ are continuous and constant.  But single pointed sets and empty sets are trivial intervals.
