Hey TheCountador.

For the expectation, you need to consider that when you are finding the expectation of one variable, you need to exhaust the possibilities for the other variable.

So for E[X] you have three options: 0,1,2. So E[X] = p(x=0)*0 + p(x=1)*1 + p(x=2)*2.

Now because you have two values of y, you need to consider p(x=a|y=0) + p(x=a|y=1) for some p(x=a). When you merge these two together you get p(x=0) = 0.2, p(x=1) = 0.6 and p(x=2) = 0.2 which gives you a different value to what you have obtained above.

Similarly for E[Y] we consider for p(y=a) = p(y=a|x=0) + p(y=a|x=1) + p(y=a|x=2) to calculate a value for p(y=a) in our expectation, so this gives us E[Y] = 0*p(y=0) + 1*p(y=1) = 0.4 (which is what you had anyway).

So E[X] = 1*0.6 + 2*0.2 = 1. E[X^2] = 1*0.6 + 4*0.2 = 1.4. E[Y] = 0.4, Var[Y] = 0.4 - 0.16 = 0.24.

E[XY] = p(x=0 and y=0)*0*0 + p(x=0 and y=1)*0*1 + p(x = 1 and y=0)*1*0 + p(x = 1 and y = 1)*1*1 + p(x = 2 and y = 0)*2*0 + p(x = 2 and y = 1)*2*1

= p(x = 1 and y = 1) + 2*p(x = 2 and y = 1) = 0.2 + 2*0 = 0.2

Cov(X,Y) = E[XY] - E[X]E[Y] = 0.2 - 1*0.4 = -0.2

Var[X-Y] = Var[X] + Var[Y] - 2Cov(X,Y) = 0.4 + 0.24 - 2*0.2 = 1.04 which is what the answer is.

Your mistake was in the covariance calculation which is Cov(X,Y) = E[XY] - E[X]E[Y]

Calculate E[XY] means you need to expand out all possibilities for X and Y (given this is discrete) and then multiply ab*p(x=a and y=b).

This is just a result of calculating g(z) where z = xy (standard expectation formulae).