Conditional expectation and variance with coin flips Let $N$ be a random number chosen uniformly at random from the set {${1, 2, 3, 4}$}. Given that $N = n$, coin A is flipped n times and coin B is flipped $(5 − n)$ times.
What is $Var(X)$?
 A: It is not unthinkable that this answer uses techniques that are not (yet) at your disposal, but makes clear that the answer of Remy is correct and that less calculations are needed to achieve this result.
First fix $n\in\{1,2,3,4\}$. Then we can write $X=A_1+\cdots+A_n+B_1+\cdots+B_{5-n}$ where the RHS is a summation of independent Bernoulli distributed random variable. The $A_i$ with parameter $0.7$ and the $B_i$ with parameter $0.5$.
Based on that we find:
$$\mathbb E[X\mid N=n]=n\times0.7+(5-n)\times0.5=2.5+n\times0.2$$
and:
$$\mathsf{Var}(X\mid N=n)=n\times0.7\times0.3+(5-n)\times0.5\times0.5=1.25-n\times0.04$$
This implies that: $$\mathbb E[X\mid N]=2.5+N\times0.2$$and:$$\mathsf{Var}(X\mid N)=1.25-N\times0.04$$
A general rule states that:$$\mathbb EX=\mathbb E[\mathbb E[X\mid N]]\tag1$$
and another general rule states that: $$\mathsf{Var}(X)=\mathbb E[\mathsf{Var}(X\mid N)]+\mathsf{Var}(\mathbb E[X\mid N])\tag2$$
Working out $(1)$ we get: $$\mathbb EX=2.5+\mathbb EN\times0.2=2.5+2.5\times0.2=3$$Working out $(2)$ we get:$$\mathsf{Var}X=[1.25-2.5\times0.04]+0.04\mathsf{Var}N=1.15+0.04\times1,25=1.15+0.05=1.2$$
A: The answer to your first question is correct, though you should explicitly mention that you are assuming $P(A)=0.5$.
In this case,
\begin{multline*}
P(A\mid HH)=\frac{P(HH\mid A)P(A)}{P(HH)}=\frac{P(HH\mid A)P(A)}{P(HH\mid A)P(A)+P(HH\mid B)P(B)}\\
=\frac{\binom{3}{2}0.7^{2}\cdot0.3\cdot0.5}{\binom{3}{2}0.7^{2}\cdot0.3\cdot0.5+\binom{3}{2}0.5^{2}\cdot0.3\cdot0.5}=\frac{147}{272}\approx0.54.
\end{multline*}
Your expectation computation looks correct, but your variance does not.
Remember,
$$
\text{Var}(X)=E\left[\left(X-E(X)\right)^{2}\right]=E[X^{2}]-(E\left[X\right])^{2}.
$$
You already know $E[X]$, so all you have to do to is compute $E[X^{2}]$.
Hint: Order of operations matters.
