generated from mwc/lab_weather
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:
parent
dc696ef25a
commit
87f87eab0b
|
@ -28,6 +28,7 @@ def get_email(people, name):
|
|||
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 +38,16 @@ def count_favorite_colors(people, name):
|
|||
>>> count_favorite_colors(family, "Raphael Chambers")
|
||||
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):
|
||||
"""Returns a list containing only those people who like the given color.
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue