After a dice is rollen seven times with the face values $N,X_1,...,X_6$, the first $N$ of the $X_i$ values are summed up. What is the expected value of $Z$?
Using the definition I have
$$\sum_z zP(Z=z)$$
And using the law of total probability, using the decomposition formed by the events $N=n$ for $n=1,...,6$
$$P(Z=z)=\sum_{n=1}^6P(Z=z|N=n)P(N=n)$$
Plugging that result back into $E(Z)$ gives
$$\sum_z z\sum_{n=1}^6P(Z=z|N=n)P(N=n)$$
Solution using @Henry 's hint:
Since the sums are finite: $$\sum_z \sum_{n=1}^6zP(Z=z|N=n)P(N=n)= \sum_{n=1}^6 \sum_zzP(Z=z|N=n)P(N=n)$$
$$\sum_{n=1}^6 P(N=n) \sum_zzP(Z=z|N=n)=\sum_{n=1}^6 E[zP(Z=z|N)]=E[E[Z|N]]$$
So in the end $$E[Z]=\sum_{k=1}^6 E[Z|N=k] P(N=k)$$
With $P(N=k)=1/6$, $E(Z|N=1)=3.5$, the expected value of one dice roll and the linearity of $E$ we get
$$E(Z)=3.5^2$$
Let $N_i$ be the indicator variable which takes the value $1$ if $N\ge i$ and $0$ otherwise.
$$E(Z)=E(X_1N_1+X_2N_2+X_3N_3+X_4N_4+X_5N_5+X_6N_6)$$ $$=E(X_1N_1)+E(X_2N_2)+E(X_3N_3)+E(X_4N_4)+E(X_5N_5)+E(X_6N_6)$$ $$=E(X_1)E(N_1)+E(X_2)E(N_2)+E(X_3)E(N_3)+E(X_4)E(N_4)+E(X_5)E(N_5)+E(X_6)E(N_6)$$ $$=(3.5)E(N_1)+(3.5)E(N_2)+(3.5)E(N_3)+(3.5)E(N_4)+(3.5)E(N_5)+(3.5)E(N_6)$$ $$=(3.5)(E(N_1)+E(N_2)+E(N_3)+E(N_4)+E(N_5)+E(N_6))$$ $$=(3.5)E(N_1+N_2+N_3+N_4+N_5+N_6)$$ $$=(3.5)E(N)=(3.5)(3.5)=12.25$$