TITLE: Construction of a continuous function which is not bounded on given interval.
QUESTION [5 upvotes]: Actual Question is :
On Which of the following spaces is every continuous (real valued) function Bounded?

$X_1=(0,1)$
$X_2=[0,1]$
$X_3=[0,1)$
$X_4 =\{t\in [0,1] : t \text { is irrational}\}$.

I could see that $1,3$ are spaces in which not every continuous function is bounded.
I could see $2$ is a spacein which not evry continuous function is bounded.
For First option I have seen that $f(x)=\frac{1}{x}$ works as it is continuous but not bounded. 
For Second option I see that continuous image of compact set is compact i.e., $f[0,1]$ is compact thus bounded.
For third option I could see that as $1$ is exculded in the domain, function is unbounded if it has a pole at $1$ So, I see that $f(x)=\frac{1}{x-1}$ would help.
For fourth option I had no clue (what i had does not help much i guess).
I would be thankful if someone can help me in this.
As this is not a serious problem I would request users to just give me hints and not to post as an answer.
Thank you.

REPLY [8 votes]: You've got the basic idea - you can just generalize it. 
Suppose $X\subset \mathbb{R}$ is such that every continuous function on $X$ is bounded. I claim that $X$ is both closed and bounded.

Suppose $c \in \overline{X}\setminus X$, then the function
$$
f(x)= \frac{1}{x-c}
$$
will be unbounded. Hence, $X$ must be closed.
If $X$ is not bounded, just take $f(x) = x$, then $f$ is unbounded.

Hence, $X$ must be compact. 
Conversely, if $X$ is compact, every continuous function is bounded, so just check which of these sets are compact.