livepython.net

255. Python Program to Make a Weekly Weather Summary

MediumPhase 2 · Practice

This one takes a few steps. You know everything it uses: lists, for loops, sum() and join().

Overview

Weather apps show a short summary of the week: the hottest day, the coldest day and the average. They also show which days were warmer than usual.

Problem Statement

Lars writes down the temperature at noon every day for a week. Each of the 7 input lines holds a day's name and its temperature, like Mon 18, in the order of the week. Read the 7 lines. Then print:

Hottest: <day> <temperature>
Coldest: <day> <temperature>
Average: <average>
Above average: <days>
  • If two or more days share the highest temperature, the hottest day is the first of them. The same goes for the coldest day.
  • Print the average with 1 decimal place.
  • Above average lists every day with a temperature higher than the average, in the order of the input, with a comma and a space between them. A day exactly at the average is not above it. Compare with the real average, not the one you print with 1 decimal place. If no day is above the average, print Above average: none.

Examples

Example 1. Input:

Mon 18
Tue 21
Wed 25
Thu 25
Fri 19
Sat 16
Sun 22

gives:

Hottest: Wed 25
Coldest: Sat 16
Average: 20.9
Above average: Tue, Wed, Thu, Sun

Why: Wed and Thu both have 25, and Wed comes first. The temperatures add up to 146, and 146 ÷ 7 = 20.857..., which shows as 20.9. Only Tue, Wed, Thu and Sun are higher than that.

Example 2. Input:

Mon -3
Tue -5
Wed 0
Thu -5
Fri 2
Sat 1
Sun -1

gives:

Hottest: Fri 2
Coldest: Tue -5
Average: -1.6
Above average: Wed, Fri, Sat, Sun

Why: the sum is -11, and -11 ÷ 7 = -1.571..., which shows as -1.6. Tue and Thu are both coldest, and Tue comes first. Sun's -1 is higher than -1.571, so Sun is above the average.

Input

Seven lines. Each line holds a day name (one word), a space, then the temperature, a whole number that can be negative. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

Four lines, as above. The tests try 7 different inputs, also a week where every day is the same and a day that is exactly at the average.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 12 · Working With Strings
solution.py
# write your code here

EXPECTED OUTPUT

1Hottest: Wed 25
2Coldest: Sat 16
3Average: 20.9
4Above average: Tue, Wed, Thu, Sun

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.