Checkpoint 1 commit 3: Wrote count_favorite_colors

My window was small, and I started writing without reading the full
docstring, which caused me to fail a test. Once I read the error, I
looked for where None appeared in friend_functions.py and realized
there was important information in there.
This commit is contained in:
Cory Dean Chung 2023-08-14 14:22:46 -04:00
parent dc696ef25a
commit 87f87eab0b
2 changed files with 11 additions and 1 deletions

View File

@ -28,6 +28,7 @@ def get_email(people, name):
for person in people: for person in people:
if person["name"] == name: if person["name"] == name:
return person["email"] 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 +38,16 @@ def count_favorite_colors(people, name):
>>> count_favorite_colors(family, "Raphael Chambers") >>> count_favorite_colors(family, "Raphael Chambers")
1 1
""" """
raise NotImplementedError() color_count = 0
for person in people:
if person["name"] == name:
for colors in person["favorite_colors"]:
color_count = color_count + 1
return color_count
return None
print count_favorite_colors(family, "Tad Winters")
print count_favorite_colors(family, "Raphael Chambers")
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.

Binary file not shown.