Lesson 39: Survey the wall
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Measure, store, then work it out
- One reading tells you little. Many readings in a list can be compared.
- First the robot collects the data. Then the program finds the highest, the lowest and the average.
- These are standard methods of solution: they come up again and again in programs and in the exam.
Words for this lesson
| Word | Meaning |
|---|---|
| total | all the values added up |
| average | the total ÷ the number of values |
| highest / lowest | the biggest / smallest value |
English
Highest, lowest and total in one loop
| Step | What to do |
|---|---|
| before the loop | highest and lowest = the first value; total = 0 |
| in the loop | bigger than highest? keep it; smaller than lowest? keep it; add to total |
| after the loop | average = total ÷ number of values |
English
In the exam
- 0478/22/F/M/23 Q2(b): write an algorithm with a single loop that outputs the average of 50 numbers stored in an array. Mark scheme: set the total to zero before the loop; loop through the array; add each element (using its index) inside the loop; calculate the average and output it after the loop.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
A wall runs along the top of the field, but it is not straight. The robot drives along it and stops 5 times. At each stop, turn left to face the wall, measure the gap with the distance sensor, store it in the list gaps (rounded), and turn back. At the end the program prints the list, for example Gaps: [610, 310, 810, 1110, 510].
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Now use the list. With one loop, find the highest gap, the lowest gap and the 총계. The average is the total ÷ the number of gaps, rounded. Print one line, for example Highest 1110, lowest 310, average 670.
출력을 보려면 '실행'을 클릭하세요.