Example 5 If a die is rolled, there are two chances to roll, one can choose to roll once or twice, but the last roll's number will be the final result. Find the mathematical expectation of the number obtained by such rolling. If there are three chances, still taking the last roll's number as the final result, find the mathematical expectation of the number obtained by such rolling.


Analyzing how many times to roll is the key point of this problem.
Solution: If only one roll is made, the mathematical expectation of the points obtained is: $\frac{1}{6} \times(1+2+3+4+5+6)=3.5$;
If two rolls are made, after the first roll, there is still one more roll opportunity, with a mathematical expectation of 3.5; thus, if the first roll is $1,2,3$ points, then re-roll. Therefore, the mathematical expectation of rolling twice is: $\frac{1}{6} \times(4+5+6)+\frac{1}{2} \times 3.5=\frac{17}{4}$.
If three rolls are made, after the first roll, there are still two more roll opportunities, with a mathematical expectation of $\frac{17}{4}=4.25$, thus if the first roll is 1,2,3,4 points, then re-roll. Therefore, the mathematical expectation of rolling three times is: $\frac{1}{6} \times(5+6)+\frac{4}{6} \times \frac{17}{4}=\frac{14}{3}$.