Lancia un dado finché non ottiene un certo numero, per esempio 3
1 2 3 4 5 6 7 |
NUM =3 ' numero magico DADO=0 While(DADO <> NUM) DADO=Math.GetRandomNumber(6) TextWindow.Write(DADO + " ") EndWhile TextWindow.WriteLine("") |
Quante volte ha lanciato il dado prima di ottenere un 3?
1 2 3 4 5 6 7 8 9 10 11 12 |
NUM =3 ' numero magico DADO=0 n =0 While(DADO <> NUM) DADO=Math.GetRandomNumber(6) TextWindow.Write(DADO + " ") n=n+1 EndWhile TextWindow.WriteLine("") TextWindow.WriteLine("-----------------------------------") TextWindow.WriteLine("Ho lanciato il dado " + n + " volte") TextWindow.WriteLine("-----------------------------------") |
Esercizi
- Lancia finché non ottiene un certo valore (3?) per un certo numero di volte (10?)
- Lancia finché la somma delle uscite non raggiunge un certo valore (100?)
- …