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 מטבעות + בונוס קטן בהשלמה הראשונה היום
עכשיו 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.
לחץ על הרץ כדי לראות את התוצא כאן.