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.
출력을 보려면 '실행'을 클릭하세요.