Mean number of attempts for 3 events to happen For example, 3 consecutive fixed tasks to complete, if one is failed, a new attempt is made from the beginning.
I'm saying an "attempt" is an attempt to complete all 3, a "try" is to try and complete a task.
Task A must be completed before B is tried, A and B must be completed before C is tried. 
Each task has the same probability $p$ of being successful.
I have calculated:  
1st task failed = $p$
1st task completed, 2nd task failed = $p(1-p)$
All 3 completed = $(1-p)^2$
and I've calculated the mean number of tries:$$p^2-3p+3$$
I tried to figure out the mean number of attempts for an "all three complete" but can't and I've been told the answer is, where w is the probability of all 3 completed: $$w + 2w(1-w) + 3w(1-w)^2 +  ... +  nw(1-w)^{(n-1)}$$
which reduces to  $\frac1w$, that is,  $$\frac1{(1-p)^2}$$
Could someone explain the maths and maybe intuition behind this please?

You can think of this problem as a Markov chain with 4 states - A, B, C, and D, where D is an absorbing state, i.e. you are done when you get there.


*

*From state A, you go back to state A with probability (w.p.) 1-p and you go to state B w.p. p

*From state B, you go back to state A w.p. 1-p and you go to state C w.p. p

*From state C, you go back to state A w.p. 1-p and you go to state D (done!) w.p. p


Now, let $T_A, T_B, T_C$ denote the expected times to transit from states A, B, C to the end of the game (state D). 
Based on the state transitions described above, you can write the following equations:
$$T_A = (1-p)(1+T_A) + p(1+T_B)$$
$$T_B = (1-p)(1+T_A) + p(1+T_C)$$
$$T_C = (1-p)(1+T_A) + p(1)$$
You can solve for $T_A$ from the above equations.
$T_A = {1 \over p} + {1 \over p^2} + {1 \over p^3}$ if I did the algebra right.
