ROUND, RANDOM and a trace · ROUND、RANDOM 与跟踪表
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
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.
中文
商店把价格四舍五入
ROUND(Value, Places)返回把Value四舍五入到Places位小数的结果。Places是整数。ROUND(3.14159, 2)是3.14。ROUND(9.6, 0)是整数10。- 考纲把
ROUND和DIV、MOD、RANDOM列在一起。
OUTPUT ROUND(3.14159, 2)
OUTPUT ROUND(9.6, 0)
English
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.
中文
骰子用 RANDOM
RANDOM()返回一个从 0 到 1(含两端)的实数。每次运行都可能不同。- 棋盘游戏的骰子是
ROUND(RANDOM() * 6, 0)。试卷在结果可以变化时才用它,所以不会要求一个固定的输出。
OUTPUT ROUND(RANDOM() * 6, 0)
English
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 |
中文
填写跟踪表
- 跟踪表就是一次干运行。循环的每一趟占一行。写下这一趟结束之后的变量。
Total从 0 开始。I = 1之后是 1。I = 2之后是 3。I = 3之后是 6。
| I | Total |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
Explore · 探索
One row per pass · 每一趟一行
A trace table records each variable after that pass of the loop. Here Total is the running sum of I. · 跟踪表记下循环这一趟之后的每个变量。这里 Total 是 I 的累积和。
DECLARE I, Total : INTEGER
Total ← 0
FOR I ← 1 TO 3
Total ← Total + I
OUTPUT I, " ", Total
NEXT I
English
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.
中文
注意
- 只有看清那一位数字时,才去处理刚好在一半的值。这里的题目不在那个边界上。
RANDOM()不是RAND。RAND属于 9618 指南,不在这份考纲里。
English
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.
中文
常见错误
ROUND的第一个参数是值,第二个是小数位数。- 跟踪表里记下的是这一行已经运行之后的值,不是你希望下一行产生的值。
English
Now you try
- The first task is
ROUND. The second prints a trace, one row per line. - Press Check answer to test it.
中文
现在你来试
- 第一题是
ROUND。第二题把跟踪表打印出来,一行一轮。 - 按检查答案来测试。
Output · 输出 ROUND(3.14159, 2) and ROUND(9.6, 0), each on its own line. · 输出 ROUND(3.14159, 2) 和 ROUND(9.6, 0),各占一行。
Click Run to see the output here. · 点击“运行”查看此处输出。
Start · 开始 Total at 0. For I from 1 to · 到 3, add I to · 到 Total and output I, a space, and Total on that line. The three lines are the trace. · Total 从 0 开始。I 从 1 到 3,把 I 加进 Total,并在同一行输出 I、一个空格和 Total。这三行就是跟踪表。
Click Run to see the output here. · 点击“运行”查看此处输出。