Night 20: Weekly report
Вы уже прошли этот вечер на Python или псевдокоде. Он засчитывается для обоих языков. При желании можете потренироваться ещё раз.
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 |
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 |

The average
- Average = total ÷ how many.
stars = [3, 9, 2, 8, 5, 1, 7]
average = sum(stars) / len(stars)
print("Average:", average)
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 и 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).
Нажмите Запустить, чтобы увидеть результат здесь.