From 87f87eab0baf411da0b6cf933f8ad3b776f5207a Mon Sep 17 00:00:00 2001 From: Cory Dean Chung Date: Mon, 14 Aug 2023 14:22:46 -0400 Subject: [PATCH] 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. --- friend_functions.py | 12 +++++++++++- friend_functions.pyc | Bin 3473 -> 3463 bytes 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/friend_functions.py b/friend_functions.py index d64b0d6..4b2e665 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -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. diff --git a/friend_functions.pyc b/friend_functions.pyc index 8704c09235c30b81b788e95c7add7f607fb8622c..e0456d371f2a20574a3f08f1272d9e4f997402e5 100644 GIT binary patch delta 567 zcmXX>O>5Lp6g}@{k|yaS%}7<+5v_t4T?mCP6jYQJ>}rsVFenU?&U@0}d^Jg>ix~w! za9!TQ|KLvM2lx}*yAYRd+~^-49%1!C;ksT+jje57la zh#uv|FcrjXzcU$Y^UV49)~60cBofgS14*2RS-DH6>JTV_xx~pM%z(ZAUCbTK94Lv6 znZPTFGQ!Cv+j6k6*H18SU`9JMaFKLJx6z}jdlaEZYjsnPeg6_3Sfh56I