Lesson 44: Follow the flowchart
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Read the flowchart, write the code
- A flowchart shows an algorithm with shapes and arrows.
- In the exam you often trace a flowchart or turn it into code.
| Shape | Meaning |
|---|---|
| rounded box | START or STOP |
| rectangle | a process: do something, set a variable |
| diamond | a decision: Yes or No |
| parallelogram | INPUT or OUTPUT |
English
Two kinds of loop

- A: test first (pre-condition loop, WHILE). The body may run 0 times.

- B: repeat first, test after (post-condition loop, REPEAT ... UNTIL). The body runs at least once.
English
In the exam
- 0478/22/F/M/24 Q8: trace a flowchart that finds the average size of groups of visitors. It inputs GroupSize until the rogue value 0; it counts the groups and totals the sizes, then outputs DIV(Total, NumberGroups).
- Try it with the exam data 7, 10, 2, 8, 3, 9, 0: NumberGroups ends at 6, Total at 39, and the output is "Average group size 6" (39 DIV 6 = 6). The 6 after the 0 is never read.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
Turn flowchart A into Python. The diamond is tested 前に the robot drives, so this is a while loop. Print Steps: and the number of steps. On the last map the box is already close: the robot must not move and must print Steps: 0.
実行ボタンをクリックして出力を確認してください。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
Now flowchart B. Here the robot drives 初項 and tests after, so the body always runs at least once. Python has no REPEAT ... UNTIL, so use while True: かつ break when the test is true. Print Count: and the count. On the last map the robot starts on a green tile: it must still drive and count until the next green tile.
実行ボタンをクリックして出力を確認してください。