generated from mwc/lab_weather
I got stuck on how to effectively use dictionaries to store and retrieve weather data. Me and my partner discussed the problem and broke it down into smaller parts and lookes back on how to fix this with a little bit of assistance.
These systems all involve multiple components working together
This commit is contained in:
@@ -17,7 +17,7 @@ def count_people(people):
|
||||
>>> count_people(friends)
|
||||
10
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
return len(people)
|
||||
|
||||
def get_email(people, name):
|
||||
"""Returns the named person's email address. If there is no such person, returns None.
|
||||
@@ -27,7 +27,10 @@ def get_email(people, name):
|
||||
>>> get_email(friends, "Tad Winters")
|
||||
None
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
for person in people:
|
||||
if person ["name"] == name:
|
||||
return person["email"]
|
||||
return None
|
||||
|
||||
def count_favorite_colors(people, name):
|
||||
"""Returns the number of colors liked by the named person. If there is no such person, returns None.
|
||||
@@ -37,7 +40,9 @@ def count_favorite_colors(people, name):
|
||||
>>> count_favorite_colors(family, "Raphael Chambers")
|
||||
1
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
for person in people:
|
||||
if person ["name"] == name:
|
||||
return len(person["favorite_colors"])D
|
||||
|
||||
def people_who_like_color(people, color):
|
||||
"""Returns a list containing only those people who like the given color.
|
||||
|
||||
@@ -21,4 +21,39 @@ 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!
|
||||
# Determine coordinates from the provided location or estimate from IP
|
||||
coords = geocode_location(location) if location else estimate_location()
|
||||
if not coords:
|
||||
print("Error: could not determine location.")
|
||||
return None
|
||||
|
||||
office = get_weather_office(coords["lat"], coords["lng"])
|
||||
if not office:
|
||||
print("Error: no weather office found for location.")
|
||||
return None
|
||||
|
||||
forecast = get_forecast(office["office"], office["x"], office["y"], metric=metric)
|
||||
if not forecast:
|
||||
print("Error: could not fetch forecast data.")
|
||||
return None
|
||||
|
||||
def icon_for(desc: str) -> str:
|
||||
d = (desc or "").lower()
|
||||
if "thunder" in d:
|
||||
return "Today will thunder ⚡"
|
||||
if "rain" in d or "shower" in d:
|
||||
return "Today will have rain showers ☔"
|
||||
if "snow" in d or "sleet" in d:
|
||||
return "Today will snow ❄"
|
||||
if "fog" in d or "haze" in d:
|
||||
return "Today will have fog, limiting your vision 🌫️"
|
||||
if "sun" in d or "clear" in d:
|
||||
return "Today will be Sunny, enjoy the outdoors! ☀️"
|
||||
if "cloud" in d or "overcast" in d:
|
||||
return "Today will be Cloudy ☁️"
|
||||
return ""
|
||||
|
||||
for day in forecast:
|
||||
symbol = icon_for(day["description"])
|
||||
print(symbol)
|
||||
display = day["name"]
|
||||
|
||||
Reference in New Issue
Block a user