Give a counterexample to demonstrate that the assumption of Y being “open in X” is necessary.

I was wondering if you could help me with this proof I have for metric spaces. I understand the theorem and the idea I just don't understand how to proceed. I am attaching the question.

Here is how I think I should proceed: So, Let U = Q(i.e. rational numbers), Y = [0,1], and X = R(i.e. real numbers).

Am I doing it right?

• Set of rationals is neither open nor closed set in R – Curious Oct 30 '17 at 8:21
• For any Y not open in X let U=Y. – DanielWainfleet Oct 30 '17 at 12:08

Assuming you meant $U = \mathbb{Q} \cap Y$, your example does not work, since $U$ is both not open in $Y$ and not open in $X$.
A counterexample can be made with $U=Y = \{0\}$ in $X=\mathbb{R}$.
Consider the metric space $X=\mathbb{R}$ and the closed subset $Y=[0,1]$. What are the open sets in $Y$? Are they all open in $X$?