Sum of Bernoulli random variables I need some help with a homework assignment. The question I'm given is: 
"Suppose that $X_1, X_2,..., X_n, W$ are independent random variables such that $X_i\sim Bin(1,0.4)$ and $P(W=i)=1/n$ for $i=1, 2 ,.., n$. Let
$Y=\sum\limits_{i=1}^W X_i=X_1+X_2+X_3+...+X_W$
That is, $Y$ is the sum of $W$ independent Bernoulli random variables. Calculate the mean and variance of $Y$"
Since $Y$ is a sum of Bernoulli random variables it would be a binomial random variable with mean $\mu=np$ and variance $\sigma^2=np(1-p)$, but I'm not sure how to handle this problem when $n$ itself is a random variable.
Can anyone show me how to approach this?
 A: Using iterated expectations and law of total variance here is the approach I would use as recommended by @Glen_b in the comments above. To use these you need the means and variances of the individual random variables. 
$$\mathbb{E}(X_1) =0.4$$
$$\mathbb{V}ar(X_1) =0.4\times0.6=0.24$$
and for $W$, 
$$\mathbb{E}(W)=\frac{1}{n}\sum_{i=1}^ni =\frac{n(n+1)}{2n}=\frac{n+1}{2}$$
$$\mathbb{V}ar(W)=\frac{1}{n}\sum_{i=1}^ni^2 -\frac{(n+1)^2}{4}
=\frac{n(n+1)(2n+1)}{2n}-\frac{(n+1)^2}{4}
=\frac{n+1}{4}\times(4n+2-(n+1))
=\frac{(n+1)\times(3n+1)}{4}.
$$
Now conditioning on $W$ and using total variance law, 
$$
\mathbb{V}ar(Y)=\mathbb{V}ar(\mathbb{E}(Y|W))+\mathbb{E}(\mathbb{V}ar(Y|W))
=\mathbb{V}ar(W\mathbb{E}(X_1))+\mathbb{E}(W\mathbb{V}ar(X_1))
=\mathbb{V}ar(W)\mathbb{E}(X_1)^2+\mathbb{E}(W)\mathbb{V}ar(X_1).
$$
Now we can use the expressions above to substitute into the last equality to get 
$$\mathbb{V}ar(Y)=\mathbb{V}ar(W)\mathbb{E}(X_1)^2+\mathbb{E}(W)\mathbb{V}ar(X_1)
=\frac{(n+1)\times(3n+1)}{4} \times \frac{4}{10} + \frac{n+1}{2}\times\frac{24}{100}
=\frac{(n+1)\times(3n+1)}{10} + \frac{12\times(n+1)}{100}
$$
