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.
This commit is contained in:
juddin2
2025-10-12 23:06:26 -04:00
parent eb80dc7c0b
commit 48698206ed

View File

@@ -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'}")