Algebraic Geometry: What am I doing wrong? This may be a very stupid question. But please explain what I am doing  wrong.
Let $k$ be an algebraically closed field. Let $f\in k[x_1,\dots, x_n]$.
Let $$D(f)=\mathbb{A}^n\setminus Z(f)$$
Then $D(f)\subseteq \mathbb{A}^n$ is open.
We can consider $\mathbb{A}^n$ as a subavariety of $\mathbb{A}^{n+1}$. Consider the polynomial ring of $n+1$ variables $k[x_1,\dots, x_n, y]$ which corresponds to $\mathbb{A}^{n+1}$. We know that $Z(fy-1)\subseteq \mathbb{A}^{n+1}$ is homeomorphic to $D(f)\subseteq \mathbb{A}^n$. This means that we can consider $D(f)$ as a closed subset of $\mathbb{A}^{n+1}$.
Fact from topology:

Let $C\subseteq Y\subseteq X$. If $C$ is closed in $X$, then $C$ is closed in $Y$.

Since $D(f)$ is closed in $\mathbb{A}^{n+1}$, shouldn't it be closed in $\mathbb{A}^n$?


Let $C\subseteq Y\subseteq X$. If $C$ is closed in $X$, then $C$ is closed in $Y$.

If you are setting $Y = \mathbb A^n$, $X=\mathbb A^{n+1}$ and $C = D(f)$, then it is clear: $D(f)$ is not closed in $\mathbb A^{n+1}$ so the condition of your statement is not satisfied (But it is true that $D(f)$ is homeomorphic to a closed subset $Z(yf-1)$ of $\mathbb A^{n+1}$)
