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?