From 48698206eda5aa7d4924250b04ccb4bf4255bbc2 Mon Sep 17 00:00:00 2001 From: juddin2 Date: Sun, 12 Oct 2025 23:06:26 -0400 Subject: [PATCH] Wrote code for weather function. Functions, programs, and distributed services all take input, process it, and produce output, often using structured data like lists or dictionaries. --- weather/weather.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/weather/weather.py b/weather/weather.py index 75fd2f6..8bcebf2 100644 --- a/weather/weather.py +++ b/weather/weather.py @@ -21,4 +21,20 @@ def print_weather(location=None, metric=False, verbose=False): When metric is True, prints out the weather in metric units. When verbose is True, prints out a more detailed report. """ - print("Not finished...") # YOUR CODE HERE! + loc = geocode_location(location) if location else estimate_location() + office = get_weather_office(loc['lat'], loc['lng']) + if not office: + print("No weather station available for this location.") + return + forecast = get_forecast(office['office'], office['x'], office['y']) + if not forecast: + print("Weather data not available.") + return + first = forecast[0] + temp = first['temperature'] + if metric: + temp = (temp - 32) * 5/9 # Convert Fahrenheit to Celsius + + print(f"Weather: {first['description']}") + print(f"Temperature: {temp:.1f}°{'C' if metric else 'F'}") +