Lesson 42: Collect the points
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Stop at the marker
- Sometimes you do not know how many values there are. The data ends with a special value that only means "stop": a rogue value.
- A condition-controlled loop (
while) runs until it meets the rogue value. - Inside the loop, totalling adds each value and counting adds 1 each time.
Words for this lesson
| Word | Meaning |
|---|---|
| rogue value | a value that marks the end of the data |
| totalling | adding each value to a running total |
| counting | adding 1 each time something happens |
English
Map 1, step by step
| Place | Tile | Total |
|---|---|---|
| 1 | red | 5 |
| 2 | blue | 7 |
| 3 | none | 7 |
| 4 | red | 12 |
| 5 | red | 17 |
| end | green | stop |
English
In the exam
- 0478/22/M/J/24 Q6(a): numbers are input until the rogue value 9999.9; total them and output the total. Mark scheme: set the total to zero before the loop; add each value to the total; a loop that stops at the rogue value (so 9999.9 is not added); output the total after the loop.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
The robot drives along a row of places, 200 mm apart. A red tile is worth 5 points, a blue tile 2 points, an empty place 0. The 緑色に見える tile is the end: it is not a place, it only says "stop". Add up the points in total. The program prints Score: and the total. The rows are different on each map.
実行ボタンをクリックして出力を確認してください。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
Now also 個体数 the places (not the green tile) in tiles, and print the average points per place, rounded to 1 decimal place: Score: 17 from 5 places, average 3.4.
実行ボタンをクリックして出力を確認してください。