I was able to write code that prints a weather forecast to my liking.

I used some code from older functions to help me write the newer program.

All these systems involve using named arguments to run certain actions.
This commit is contained in:
kdang
2025-11-07 09:24:40 -05:00
parent 78da86d231
commit 4eb17103c6
2 changed files with 28 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ def count_people(people):
>>> count_people(friends) >>> count_people(friends)
10 10
""" """
raise NotImplementedError() return len(people)
def get_email(people, name): def get_email(people, name):
"""Returns the named person's email address. If there is no such person, returns None. """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") >>> get_email(friends, "Tad Winters")
None None
""" """
raise NotImplementedError() for person in people:
if person["name"] == name:
return person["email"]
return None
def count_favorite_colors(people, name): def count_favorite_colors(people, name):
"""Returns the number of colors liked by the named person. If there is no such person, returns None. """Returns the number of colors liked by the named person. If there is no such person, returns None.
@@ -37,7 +40,10 @@ def count_favorite_colors(people, name):
>>> count_favorite_colors(family, "Raphael Chambers") >>> count_favorite_colors(family, "Raphael Chambers")
1 1
""" """
raise NotImplementedError() for person in people:
if person["name"] == name:
return len(person["favorite_colors"])
return None
def people_who_like_color(people, color): def people_who_like_color(people, color):
"""Returns a list containing only those people who like the given color. """Returns a list containing only those people who like the given color.
@@ -57,7 +63,10 @@ def people_who_like_color(people, color):
>>> people_who_like_color(family, "indigo") >>> people_who_like_color(family, "indigo")
[] []
""" """
raise NotImplementedError() for person in people:
if person["favorite_colors"] == color:
return people
return None
def count_people_who_like_color(people, color): def count_people_who_like_color(people, color):
"""Returns the number of people who like a given color. """Returns the number of people who like a given color.
@@ -67,7 +76,9 @@ def count_people_who_like_color(people, color):
>>> count_people_who_like_color(family, "orange") >>> count_people_who_like_color(family, "orange")
1 1
""" """
raise NotImplementedError() for person in people:
if person["favorite_colors"] == color:
return len(people)
def get_color_dict(people): def get_color_dict(people):
"""Returns a dict showing how many people like each color. """Returns a dict showing how many people like each color.

View File

@@ -21,4 +21,15 @@ def print_weather(location=None, metric=False, verbose=False):
When metric is True, prints out the weather in metric units. When metric is True, prints out the weather in metric units.
When verbose is True, prints out a more detailed report. When verbose is True, prints out a more detailed report.
""" """
print("Not finished...") # YOUR CODE HERE! if location:
coordinates = geocode_location(location)
else:
coordinates = estimate_location()
office = get_weather_office(coordinates["lat"], coordinates["lng"])
forecast = get_forecast(office["office"], office["x"], office["y"], metric=metric)
for day in forecast:
display = day["name"] + " Temperature: " + str(day["temperature"]) + " Wind Speed: " + str(day["wind_speed"]) + " Weather: " + day["description"]
print(display)