Skip to content
dreamcode
dreamcode
Projects
Weather Window
Independent projectPython
Reward: +340 XP
PROJECT BRIEF

Weather Window

A forecast feed sends a list of dictionaries such as {"temp": 20, "condition": "rainy"}. Write analyze_weather(forecasts) that returns a summary dictionary with three keys:

  • avg_temp: the average temperature, rounded to one decimal place
  • conditions: each condition once, in the order it first appears
  • warmest: the condition on the warmest day (the first one if there is a tie)

An empty feed returns {"avg_temp": 0, "conditions": [], "warmest": None}.

Examples
analyze_weather([{'temp': 20, 'condition': 'rainy'}, {'temp': 24, 'condition': 'cloudy'}, {'temp': 22, 'condition': 'rainy'}])
{'avg_temp': 22, 'conditions': ['rainy', 'cloudy'], 'warmest': 'cloudy'}
analyze_weather([])
{'avg_temp': 0, 'conditions': [], 'warmest': None}
project.py
PYTHON
Saved as you type

Tests

0 of 4 passing
  • three days
    analyze_weather([{'temp': 20, 'condition': 'rainy'}, {'temp': 24, 'condition': 'cloudy'}, {'temp': 22, 'condition': 'rainy'}])
    expected {'avg_temp': 22, 'conditions': ['rainy', 'cloudy'], 'warmest': 'cloudy'}
  • empty feed
    analyze_weather([])
    expected {'avg_temp': 0, 'conditions': [], 'warmest': None}
  • average rounds to one place
    analyze_weather([{'temp': 10, 'condition': 'fog'}, {'temp': 11, 'condition': 'fog'}, {'temp': 11, 'condition': 'sun'}])
    expected {'avg_temp': 10.7, 'conditions': ['fog', 'sun'], 'warmest': 'fog'}
  • single day
    analyze_weather([{'temp': -3, 'condition': 'snow'}])
    expected {'avg_temp': -3, 'conditions': ['snow'], 'warmest': 'snow'}
On the line
+340 XP
Pass all 4 tests to claim it.