How I get the nth derivative of the function $y = e^x x^2$ I'm totally confused. Please anyone help me.
$y' = e^x x^2 + 2 e^xx$
$y''= e^x x^2 + 4 e^xx + 2e^x$
$y'''= e^x x^2 + 6 e^xx + 6 e^x$
next $y''''$ but I failed to get any pattern.

We need to find an expression to $\frac{d^{n}y}{dx^{n}}$.
Observe that you can use $\underline{\text{product rule}}$ and $\underline{\text{chain rule}}$ in each calculation of the derivative to $y$. Indeed
$$\frac{dy}{dx}=e^{x}(x^{2}+2x+(1-1)(1))$$
$$\frac{d^{2}y}{dx^{2}}=e^{x}(x^{2}+2(2)x+(2-1)(2))$$
$$\frac{d^{3}y}{dx^{3}}=e^{x}(x^{2}+2(3)x+(3-1)(3))$$
$$\frac{d^{4}y}{dx^{4}}=e^{x}(x^{2}+2(4)x+(4-1)(4))$$
$$\frac{d^{5}y}{dx^{5}}=e^{x}(x^{2}+2(5)x+(5-1)(5))$$
so, by an inductive argument, we can see that
$$\boxed{\frac{d^{n}y}{dx^{n}}=e^{x}(x^{2}+2nx+(n-1)(n)), \quad n \in \mathbb{N}}$$
