Lesson 36: Retrace the route
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Remember the way
- The robot follows arrows on the floor. To come back, it must remember every move.
- A list stores the moves in order, like a notebook: first move at the top, last move at the bottom.
- To go home, read the notebook from the bottom up and do the opposite of each turn.
Words for this lesson
| Word | Meaning |
|---|---|
| list / array | many values under one name |
| element | one value in the list |
| index | the position of an element: 0, 1, 2 … |
| append | add an element to the end |
English
The way back
| Way there (in order) | Way back (last first) |
|---|---|
| forward | forward |
| turn right | turn left |
| turn left | turn right |
- Start the way back with a 180° turn.
English
In the exam
- 0478/22/M/J/22 Q3(a): describe a one-dimensional array. Mark scheme: a list of items of the same data type, stored under a single identifier, with an index to identify each element; plus an example declaration. In your program
movesis the identifier, every element is a string, andmoves[i]uses the index. - Exam pseudocode arrays usually start at index 1; Python lists start at 0.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Coloured tiles on the floor are arrows: after each 200 mm, a red tile means turn right, a blue tile means turn left, and the green tile is the end. The robot already follows them. Store every move in the list moves: "F" for each forward step, "R" 或 "L" for each turn. At the end it prints how many moves it made, for example 11 moves. Each map has a different route.
点击“运行”查看此处输出。
难度 4/5 · 今日首次完成可获 280 金币及少量额外奖励
Now drive back to the start using only the list, not the tiles. Turn round (180°), then read moves from the last to the first. A forward step is still forward, but every turn is the other way: "R" becomes a left turn and "L" a right turn. The goal is the start square.
点击“运行”查看此处输出。