Lesson 42: Collect the points
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
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.
Độ khó 3/5 · 200 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
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 hơn xanh lá 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.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 4/5 · 280 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Now also số lượng 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.
Nhấn Chạy để xem kết quả ở đây.