I know this question is frequently asked on this website, but I'm not sure if my proof is correct:
Question. Prove that if each factor space $X_n$, $n=1,2,\cdots$, is separable, then so is the product space $X=\prod_{n\in\mathbb N} X_n$.
My Attempt. Let $\{X_n:n\in\mathbb N\}$ be a countable set of separable spaces, and for each $n\in\mathbb N$ let $A_n$ be a countable dense subset of $X_n$. Then $A:=\prod_{n\in\mathbb N}A_n$ is clearly countable. Now for any $x\in X$, let $O$ be an open set containing $x$. Then there exists a subset $U:=\prod_{n\in\mathbb N} U_n$ of $O$ with $U_n$ being open in $X_n$ for each $n\in\mathbb N$. Now since $A_n$ is dense in $X_n$ for any $n\in\mathbb N$, the intersection $U_n\cap A_n$ is nonempty. Then taking $y_n\in U_n\cap A_n$ for each $n\in\mathbb N$, we have that $y=(y_1,y_2,\cdots)$ is a member of $A\cap O$ and hence $A$ is dense in $X$. Therefore $X$ is separable.
What I want to ask is that in my attempt, I haven't used the fact that $U_n=X_n$ for all but finitely many $n$. Is this proof still correct, or did I miss something? All help would be appreciated.