TITLE: To show a morphism of affine k-varieties which is surjective on closed points is surjective
QUESTION [7 upvotes]: This is a exercise from Ravi Vakil's Foundations of Algebraic Geometry, Ex 7.4.E.

Assume Chevalley's theorem. Show that a morphism of affine $k$-varieties $\pi:X \rightarrow Y$ is surjective iff it is surjective on closed points (i.e. if every closed point of $Y$ is the image of a closed point of $X$).

I want to show 'if' part. Since $X,Y$ are both $k$-varieties so $\pi$ is morphism of Noetherian scheme. By Chevalley's thm, $\pi(X)=\cup_{i=1}^{N}O_i\cap C_i$, where $O_i$ are open, $C_i$ are closed and $\{O_i \cap C_i\}$ are disjoint. Since $\pi$ is surjective on closed points, we know $\pi(X)$ is dense. If I can prove $\pi(X)$ is open, then I am done. Can anyone provide some hints for me?

REPLY [8 votes]: Here's a slightly different take:
Suppose that the map is not surjective, then take $p \notin \operatorname{im}(\pi)$. By Chevally's theorem, the image is constructible, whence the complement is as well, so is a disjoint union of locally closed sets $U_i\cap Z_i$ where $U_i$ is open and $Z_i$ is closed, say $p \in U_1\cap Z_1$. The closed points of $Z_1$ are dense*, so $U_1\cap Z_1$ contains a closed point. But this is impossible, since $U_1\cap Z_1$ was part of the complement of the image, and the image contains all the closed points.
*Recall that the closed points of $\operatorname{Spec}(A)$ for $A$ a finitely generated $k-$algebra are dense, and thatif $V(I)$ is a closed subset, it is homeomorhpic to $\operatorname{Spec}(A/I)$, where $A/I$ is also a finitely generated $k-$algebra. This is enough for the task at hand, but it is useful to observe that if $X$ is scheme locally of finite type over a field $k$, and $Z\subset X$ is closed, the closed points of $Z$ are dense in $Z$.