Files
lab_weather/friend_functions.py
caglazir 581f77b463 I worked on the friends functions and the weather.
Checkpoint 1: I kind of hated how the test_friend_functions worked.
It was overstimulating and I had to move my friend_functions code into
the people code to test them out. I did end up getting correct results
for the functions that I created but I couldm't figure out what was
happening to these results when I ran them with test_friend_functions
instead. I took too much time getting frustrated on this part so I
decided to move on after thinking that I got the general gist of it.
I also talked to Molly and we both thought this part was frustrating and
moved on after a while.

Checkpoint 2: This part of the lab was less frustrating than the one
before. I guess understanding what the weather API did helped a lot as well
as the practice from frined functions to call things appropriately.
My general understanding of what all these systems have in common is that
they all rely on inputs one way or the other. For more complex systems such
as the weather that draws from online data, we also have to be careful with
how to integrate and recall outputs to continue and then categorize them
as we need.
2025-10-25 17:39:49 -04:00

77 lines
1.8 KiB
Python

# friend_functions.py
# ------------
# By MWC Contributors
#
# Each of the functions below expects a list of dictionaries as its first
# argument. Two examples of the expected input are provided in people.family
# and people.friends.
# Your job is to complete these functions. Remove the NotImplementedError from
# each and instead write code which returns the expected values.
def count_people(people):
count=0
for person in people:
if "name" in person:
count=count+1
print(count)
def get_email(people, name):
email=""
for person in people:
if person["name"] == name:
email=person["email"]
print(f'"{email}"')
return
else:
print("None")
def count_favorite_colors(people, name):
for person in people:
if person["name"] == name:
numcolor=len(person["favorite_colors"])
print(numcolor)
return
else:
print("None")
def people_who_like_color(people, color):
for person in people:
if color in person["favorite_colors"]:
print(person)
else:
print([])
def count_people_who_like_color(people, color):
colorcount=0
for person in people:
if color in person["favorite_colors"]:
colorcount=colorcount+1
print(colorcount)
def get_color_dict(people):
"""Returns a dict showing how many people like each color.
Any color liked by any of the people will be included, and only colors
liked by someone will be included. The order of items in the dict doesn't matter.
>>> get_color_dict(family)
{
"aqua": 2,
"red": 2,
"blue": 2,
"black": 2,
"white": 1,
"grey": 1,
"yellow": 2,
"orange": 1,
}
"""
raise NotImplementedError()