Lesson 44: Follow the flowchart
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 |
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.
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.
Нажмите Запустить, чтобы увидеть результат здесь.