I'm trying to derivate the equation
$$\text{tr}(A) = \sum_n\langle n \vert A \vert n\rangle $$
This equation represents the trace of an operator that is an observable in quantum mechanics, so it is an hermitian operator. The question asks to derive the above equation with the equation
$$\rho = \sum_nP_n\vert n \rangle \langle n \vert $$
Were $P_n$ is a probability given by
$$P_n = \langle n\vert \rho \vert n \rangle$$
And the hint given is that we can use the property of trace $\text{tr}(\vert \alpha \rangle \langle \beta \vert) = \langle \beta \vert \alpha \rangle$.
My attempt: $$\text{tr}\left(\rho A\right) = \text{tr}\left(\sum_nP_nA\vert n \rangle \langle n \vert\right) = \sum_nP_n\text{tr}(A\vert n \rangle \langle n \vert) \stackrel{(1)}{=} \sum_n P_n\langle n\vert A \vert n \rangle$$
And then I'm stuck. What can I do now? The equality $(1)$ is correct?
There is not really a "derivation" to the equation $$ \text{tr}(A) = \sum_n\langle n \vert A \vert n\rangle. $$
Let me explain. The trace of an operator from $A: \mathbb{C^n} \to \mathbb{C^n}$ is defined as the sum of the entries on the diagonal of $A,$ and it is not a basis-dependent property of $A$. What you see in bra-ket notation above is just that, first you multiply the matrix $A$ by the $e_n$ basis vector (in whatever basis you want), then you dot product it with the same basis vector. This gives you the matrix element $A_{nn}.$ Then, you sum those up and you have the trace of $A$. The infinte dimensional case isn't hard to generalize to, and I doubt they worry about such details in physics.
For example, take $$A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}$$ We see that the trace of this matrix is tr$(A) = 1 + 5 + 9 = A_{11} + A_{22} + A_{33}.$ In bra-ket notation, we can calculate each term like $$A_{11} = \langle 1 | A | 1 \rangle = \begin{pmatrix} 1\\0\\0 \end{pmatrix}^T \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix} \begin{pmatrix} 1\\0\\0 \end{pmatrix} = \begin{pmatrix} 1\\0\\0 \end{pmatrix}^T \begin{pmatrix} 1\\4\\7 \end{pmatrix} = 1 + 0 + 0$$ Likewise, this could be done for basis vectors $e_2 = |2\rangle$ and $e_3 = |3\rangle$ to get $A_{22}$ and $A_{33}.$
Anyway, as far as the derivation you attempted, I'd do something like $$ A = \sum_n A |n\rangle \langle n| = \sum_n |A n\rangle \langle n|,$$ So $$\text{tr}(A) = \sum_n \text{tr}(|A n\rangle \langle n|) = \sum_n \langle n|An\rangle := \sum_n \langle n|A|n\rangle.$$
Its not much of a derivation, but perhaps that is what they wanted to see.