From f9ec3295a6d5d02acf51b6420de99806fe0e78ee Mon Sep 17 00:00:00 2001 From: Chris Mekelburg Date: Sun, 13 Oct 2024 22:25:14 -0400 Subject: [PATCH] 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. --- friend_functions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/friend_functions.py b/friend_functions.py index 25275c8..c4741f0 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -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) \ No newline at end of file +print("People who like red:", like_color) + +count_color = count_people_who_like_color(friends, "red") +print("# who like red:", count_color) \ No newline at end of file