Night 20: Weekly report
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: weekly report
- Your pet counted the stars every night this week. Tonight you write a report.
- You will learn one thing: three classic loops: total, largest and smallest.
Words for tonight
| Word | Meaning |
|---|---|
| total | all the numbers added together |
| largest / smallest | the biggest / the least |
| average | the total divided by how many numbers there are |
English
The total
- A running total, like night 7. Start at 0 and add each element.
DECLARE Stars : ARRAY[1:4] OF INTEGER
DECLARE Index, Total : INTEGER
Stars[1] ← 3
Stars[2] ← 9
Stars[3] ← 2
Stars[4] ← 8
Total ← 0
FOR Index ← 1 TO 4
Total ← Total + Stars[Index]
NEXT Index
OUTPUT "Total: ", Total
OUTPUT "Average: ", Total / 4

English
The largest
- Start with the first element. Look at the rest. Keep any bigger one.
DECLARE Stars : ARRAY[1:4] OF INTEGER
DECLARE Index, Largest : INTEGER
Stars[1] ← 3
Stars[2] ← 9
Stars[3] ← 2
Stars[4] ← 8
Largest ← Stars[1]
FOR Index ← 2 TO 4
IF Stars[Index] > Largest THEN
Largest ← Stars[Index]
ENDIF
NEXT Index
OUTPUT "Most stars: ", Largest
- For the smallest, use
<instead of>.
English
Three patterns for the exam
| You want | Start with | In the loop |
|---|---|---|
| total | Total ← 0 |
Total ← Total + Stars[Index] |
| largest | Largest ← Stars[1] |
keep it if Stars[Index] > Largest |
| smallest | Smallest ← Stars[1] |
keep it if Stars[Index] < Smallest |
- These three loops come up in Paper 2 again and again. Now write your pet's report!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet counted stars for 7 nights. Use a FOR loop to add them up in Total. Output Total: 35.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Find the most stars on one night in Largest, and the fewest in Smallest. Output them on two lines: 9, then 1.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Work out the average: the total divided by 7. Output it: 5.0.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Which night was best? Keep the 색인 of the biggest number in Best. Output Best night: 2.
출력을 보려면 '실행'을 클릭하세요.