ROUND, RANDOM and a trace · ROUND, RANDOM e uma traçagem
A shop rounds a price
ROUND(Value, Places)returnsValuerounded toPlacesdecimal places.Placesis an integer.ROUND(3.14159, 2)is3.14.ROUND(9.6, 0)is the whole number10.- The syllabus lists
ROUNDwithDIV,MODandRANDOM.
Uma loja arredonda um preço
ROUND(Value, Places)retornaValuearredondado paraPlacescasas decimais.Placesé um inteiro.ROUND(3.14159, 2)é3.14.ROUND(9.6, 0)é o número inteiro10.- O programa de estudos lista
ROUNDcomDIV,MODeRANDOM.
OUTPUT ROUND(3.14159, 2)
OUTPUT ROUND(9.6, 0)
A dice uses RANDOM
RANDOM()returns a real from 0 to 1, including both ends. Each run can differ.- A board-game dice is
ROUND(RANDOM() * 6, 0). The paper uses it when the result may vary, so you are not asked for one fixed output.
Um dado usa RANDOM
RANDOM()retorna um real de 0 a 1, incluindo ambas as extremidades. Cada execução pode diferir.- Um dado de jogo de tabuleiro é
ROUND(RANDOM() * 6, 0). O papel o usa quando o resultado pode variar, então você não é perguntado por uma saída fixa.
OUTPUT ROUND(RANDOM() * 6, 0)
Fill a trace table
- A trace table is a dry run. One row is one pass of the loop. You write the variables after that pass.
Totalstarts at 0. AfterI = 1it is 1. AfterI = 2it is 3. AfterI = 3it is 6.
| I | Total |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
Preencha uma tabela de traçado
- Uma tabela de traçado é uma execução em seco. Uma linha é uma passagem do loop. Você escreve as variáveis depois dessa passagem.
Totalcomeça em 0. ApósI = 1é 1. ApósI = 2é 3. ApósI = 3é 6.
| I | Total |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
One row per pass · Uma linha por passagem
A trace table records each variable after that pass of the loop. Here Total is the running sum of I. · Uma tabela de traçagem registra cada variável após aquela passagem do loop. Aqui Total é a soma acumulada de I.
DECLARE I, Total : INTEGER
Total ← 0
FOR I ← 1 TO 3
Total ← Total + I
OUTPUT I, " ", Total
NEXT I
Watch out
- Round a half only when you have checked the digit. The tasks here are not on a halfway value.
RANDOM()is notRAND.RANDbelongs to the 9618 guide, not to this syllabus.
Atenção
- Arredonde apenas metade quando tiver verificado o dígito. As tarefas aqui não estão em um valor exato.
RANDOM()não éRAND.RANDpertence ao guia 9618, não a este programa de estudos.
Common mistakes
ROUNDtakes the value first and the number of places second.- In a trace, record the values after the line has run, not the values you hope the next line will produce.
Erros comuns
ROUNDrecebe o valor primeiro e o número de casas depois.- Em uma trilha, registre os valores após a linha ter sido executada, não os valores que você espera que a próxima linha produza.
Now you try
- The first task is
ROUND. The second prints a trace, one row per line. - Press Check answer to test it.
Agora você tenta
- A primeira tarefa é
ROUND. A segunda imprime um traçado, uma linha por linha. - Pressione Check answer para testá-lo.
Output · Saída ROUND(3.14159, 2) and · e ROUND(9.6, 0), each on its own line. · Imprima ROUND(3.14159, 2) e ROUND(9.6, 0), cada um em sua própria linha.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Start · Iniciar Total at 0. For I from 1 to · até 3, add I to · até Total and output I, a space, and Total on that line. The three lines are the trace. · Comece Total em 0. Para I de 1 a 3, adicione I a Total e saia com I, um espaço e Total naquela linha. As três linhas são a traçagem.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.