count_people_who_like_color is working

I think I got this function working, but it's difficult to decipher the
error messages in the test_friend_functions program. I'm going to attempt
the last function and then revisit anything that is still giving an error.
This commit is contained in:
Chris Mekelburg 2024-10-13 22:25:14 -04:00
parent 36bee1bf5f
commit f9ec3295a6
1 changed files with 9 additions and 2 deletions

View File

@ -83,7 +83,11 @@ def count_people_who_like_color(people, color):
>>> count_people_who_like_color(family, "orange")
1
"""
raise NotImplementedError()
like_color2 = []
for person in people:
if color in person["favorite_colors"]:
like_color2.append(person["name"])
return len(like_color2)
def get_color_dict(people):
"""Returns a dict showing how many people like each color.
@ -118,4 +122,7 @@ favcolor = count_favorite_colors(friends, "Yulix Reynolds")
print ("# of fav colors is", favcolor)
like_color = people_who_like_color(family, "aqua")
print("People who like red:", like_color)
print("People who like red:", like_color)
count_color = count_people_who_like_color(friends, "red")
print("# who like red:", count_color)