Prove that $G$ is an open interval for two-valued continuous function $f$ 
Suppose $G\subset \mathbb R$ is a non-empty open set such that the function $f:G \rightarrow \{0,1\}$ is a two-valued function and is continuous. Show that any two-valued function on $G$ is a constant if and only if the set $G$ is an open interval.

I am concerning about the construction of open set for set $G$ and have no idea to start off with. 

If $G$ is an open interval then IVP tells you that if $f$ if takes both the values $0$ and $1$ then it must take all values in between. This proves one way.
For the other way use the fact any open set is a disjoint union of open intervals. If $G$ is a union of two or mote intervals define $f$ to be $1$ on one of them and $0$ on all the others. You will get a continuous function taking both the values $0$ and $1$ (and no other value).
