Lazo Lab Sign up

App 4: Weather App with a Real API / Build the weather app

Lesson 8 of 10

A 3-day forecast

Ask the API for daily data too. It returns lists, one item per day, which you can loop over together with zip.

Key points

  • daily=temperature_2m_max,temperature_2m_min
  • zip() walks several lists together
  • forecast_days=3
params = {"latitude": lat, "longitude": lon, "forecast_days": 3, "timezone": "auto",
          "daily": "temperature_2m_max,temperature_2m_min"}
d = requests.get("https://api.open-meteo.com/v1/forecast", params=params, timeout=10).json()["daily"]
for day, hi, lo in zip(d["time"], d["temperature_2m_max"], d["temperature_2m_min"]):
    print(f"{day}: {lo}° to {hi}°")

Your turn

Add a forecast option to your app.

Watch a video on thisOpens YouTube search results for “A 3-day forecast” in a new tab

Quiz · +10 XP

What does zip(a, b) do?

Log in to save progress and earn XP.