From 86a3efa082320dd6d38d3facfd044cfbe58e39e8 Mon Sep 17 00:00:00 2001 From: Aminah Date: Tue, 29 Oct 2024 17:07:12 -0400 Subject: [PATCH] resubmit --- friend_functions.py | 12 ++++++++++-- weather.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ weather.py.save | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 weather.py create mode 100644 weather.py.save diff --git a/friend_functions.py b/friend_functions.py index 6f5ecf7..b4dfee7 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -17,7 +17,11 @@ def count_people(people): >>> count_people(friends) 10 """ - raise NotImplementedError() + count = 0 + for x in people: + count= count+1 + return count + def get_email(people, name): """Returns the named person's email address. If there is no such person, returns None. @@ -27,7 +31,11 @@ def get_email(people, name): >>> get_email(friends, "Tad Winters") None """ - raise NotImplementedError() + for person in people: + if person["name"] == name: + if "email" in person: + 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. diff --git a/weather.py b/weather.py new file mode 100644 index 0000000..740a6da --- /dev/null +++ b/weather.py @@ -0,0 +1,44 @@ +from argparse import ArgumentParser +from weather.weather_apis import ( + geocode_location, + estimate_location, + get_weather_office, + get_forecast +) +def print_weather(location=None, metric=False, verbose=False): + """Prints out a weather report using the provided location, or using + the user's current location if no location was provided. + When metric is True, prints out the weather in metric units. + When verbose is True, prints out a more detailed report. + """ + print("Not finished...") + + if location: + coordinates = geocode_location(location) + if not coordinates: + print("Error: Location not found. ") + return + else: + coordinates = estimate_location() + if not coordinates: + print("Error: Unable to estimate location.") + return + office_info = get_weather_office(coordinates['lat'], coordinates['lng']) + if not office_info: + print("Error: Weather office not found for this location.") + return + forecast = get_forecast(office_info['office'], office_info['x'], office_info['y'], metric=metric) + if not forecast: + print("Error: Forecast data is unavailable.") + return + temp_unit = "°C" if metric else "°F" + print(f"Weather Forecast for {location or 'your location'}:") + for period in forecast: + + temp = period['temperature'] + description = period['description'] + wind = period['wind_speed'] + wind_dir = period['wind_direction'] + print(f"{period['name']}: {temp}{temp_unit}, {description}") + if verbose: + print(f" Wind: {wind} {wind_dir}") \ No newline at end of file diff --git a/weather.py.save b/weather.py.save new file mode 100644 index 0000000..0d70d96 --- /dev/null +++ b/weather.py.save @@ -0,0 +1,43 @@ + + + + + + + + + + +^X +^X + + + + + + + + + + + + + + + + + + + + + + + +ls + + + + + + +