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: quick tools for lists of numbers:
sum,min,max.
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
Three quick tools
stars = [3, 9, 2, 8, 5, 1, 7]
print("Total:", sum(stars))
print("Most:", max(stars))
print("Fewest:", min(stars))
| Tool | Gives |
|---|---|
sum(stars) |
35 |
max(stars) |
9 |
min(stars) |
1 |
len(stars) |
7 |

English
The average
- Average = total ÷ how many.
stars = [3, 9, 2, 8, 5, 1, 7]
average = sum(stars) / len(stars)
print("Average:", average)
English
When you need the position
maxgives the biggest value. But which night was it?- Use a loop and remember the position of the best so far.
stars = [3, 9, 2, 8, 5, 1, 7]
best = 0
for i in range(len(stars)):
if stars[i] > stars[best]:
best = i
print("Best night:", best + 1)
- Week 3 is almost done. Now write your pet's report!
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Your pet counted stars for 7 nights: stars = [3, 9, 2, 8, 5, 1, 7]. Print the total with sum. The output is 35.
点击“运行”查看此处输出。
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Print the most stars on one night, then the fewest, on two lines. The output is 9 and then 1.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Work out the average: the total divided by the number of nights. Use sum and len. Print it: 5.0.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Which night was best? Use a loop to find the position of the biggest number. Print Best night: 2 (night 1 is position 0).
点击“运行”查看此处输出。