conditioning problem Let X be a random variable with $P(X=1)=P(X=2)= \frac{1}{2}$, and let the conditional distribution of $Y$ given $X$ be an exponential with rate $X$. Find $E[Y]$ and $\operatorname{Var}[Y]$.
What I could think of is to use the fact that $E[Y]=E[E[Y|X]$. So I got
$$
E[Y]=E[Y|X=1]P(X=1)+E[Y|X=2]P(X=2).
$$
Am I going to the right direction?
 A: You are on the right track!
For a fixed number $x$, an exponential variable with rate $x$ has mean $\frac{1}{x}$; so, $\mathbb{E}[Y\mid X]=\frac{1}{X}$. 
To see this more formally: an exponential variable with rate $x$ has density $p(t)=xe^{-xt}$. So, conditioned on $X=1$, $Y$ is exponential distributed with rate $1$ and therefore has density $p(t)=e^{-t}$, and we get
$$
\mathbb{E}[Y\mid X=1]=\int_{0}^{\infty}t\,p(t)\,dt=\int_0^{\infty}te^{-t}\,dt=1=\frac{1}{1}.
$$
Similarly, conditioned on $X=2$, $Y$ is exponentially distributed with rate $2$ and therefore has density $p(t)=2e^{-2t}$, and so
$$
\mathbb{E}[Y\mid X=2]=\int_0^{\infty}t\,p(t)\,dt=\int_0^{\infty}2te^{-2t}\,dt=\frac{1}{2}.
$$
So, notice: in each case, we have $\mathbb{E}[Y\mid X]=\frac{1}{X}$!
Thus, as you point out,
$$
\mathbb{E}[Y]=\mathbb{E}[\mathbb{E}[Y\mid X]]=\mathbb{E}\left[\frac{1}{X}\right]=\frac{1}{1}\cdot\frac{1}{2}+\frac{1}{2}\cdot\frac{1}{2}=\frac{3}{4}.
$$
Now, you need to compute the variance.  But remember, we can write variance as an expectation:
$$
\text{Var}[Y]=\mathbb{E}[(Y-\mathbb{E}[Y])^2]=\mathbb{E}[Y^2]-\mathbb{E}[Y]^2.
$$
So, you are left to do the same thing here as you did before, but now for $Y^2$ instead of $Y$.  So, you need to try to get a handle on $\mathbb{E}[Y^2\mid X]$.
A: Another way (slower):
$$
\mathbf{E}Y= \mathbf{E}[Y|X=1]P(X=1)+\mathbf{E}[Y|X=2]P(X=2)=\frac{1}{2}\int_{0}^{\infty}ye^{-y}dy + 1 \cdot \int_{0}^{\infty}ye^{-2y}dy\\
=\frac{1}{2} \cdot 1 +1 \cdot \frac{1}{4}=\frac{3}{4}\\
\mathbf{Var}Y=\mathbf{E}Y^2-(\mathbf{E}Y)^2 = \mathbf{E}[Y^2|X=1]P(X=1)+\mathbf{E}[Y^2|X=2]P(X=2)-(\mathbf{E}Y)^2\\
\mathbf{E}[Y^2|X=1]=\int_{0}^{\infty}y^2e^{-y}dy\\
\mathbf{E}[Y^2|X=2]=2 \int_{0}^{\infty}y^2e^{-2y}dy
$$
