Let ${X_n, n\in N}$ be an iid sequence of psitive rrvs and let $K$ be a rrv independent of this sequence and taking its values in $N$ with $P(K=k)=p_k$. Consider the rrv $Z=\sum_{n=1}^{K} X_n$. Suppose that $E(X_n) <\infty$. Then show $E(Z)=E(K)E(X_n)$
My attempt is that since $K$ is independent of $X_n$ then how can i apply independence formula for expectation?
$EZ=\sum_k E(Z|K=k)P(K=k)$ $=\sum_k (kEX_1) P(K=k)=E(X_1) \sum_k kP(Z=k)=EX_1EK$. Note that $EX_n$ doe not depend on $n$ since $(X_I)$ is i.i.d..