From a5e214b29f3d828339e74e0b3b51fea734cc1e90 Mon Sep 17 00:00:00 2001 From: njmason2 Date: Sat, 18 Oct 2025 05:36:40 -0400 Subject: [PATCH] friend_functions.py --- friend_functions.py | 32 +++++++++++++++++++------------- test_friend_functions.py | 32 ++++++++++++++++---------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/friend_functions.py b/friend_functions.py index 9c77bbd..faa78de 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -20,22 +20,23 @@ -def get_email(people, name): - """Returns the named person's email address. If there is no such person, returns None. +# def get_email(people, name): +# """Returns the named person's email address. If there is no such person, returns None. - >>> get_email(family, "Tad Winters") - "ligula.aenean@hotmail.edu" - >>> get_email(friends, "Tad Winters") - None - """ +# >>> get_email(family, "Tad Winters") +# "ligula.aenean@hotmail.edu" +# >>> get_email(friends, "Tad Winters") +# None +# """ - for person in people: - if (person["name"]==name): - return person["email"] +# for person in people: +# if (person["name"]==name): # on the left is the syntax +# # for a dict within a list lookup +# return person["email"] # dict within a list lookup - return None +# return None # reached the end of the list without a match -#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. >>> count_favorite_colors(family, "Tad Winters") @@ -43,7 +44,12 @@ def get_email(people, name): >>> count_favorite_colors(family, "Raphael Chambers") 1 """ -# raise NotImplementedError() + for person in people: + if (person["name"]==name): # for a dict within a list lookup + return len(person["favorite_colors"]) # count of list elements in a dict within a list + + return None # reached the end of the list without a match + #def people_who_like_color(people, color): """Returns a list containing only those people who like the given color. diff --git a/test_friend_functions.py b/test_friend_functions.py index 7fef28d..3e8383c 100644 --- a/test_friend_functions.py +++ b/test_friend_functions.py @@ -10,8 +10,8 @@ from unittest import TestCase, main from people import friends, family from friend_functions import ( # count_people, - get_email, - # count_favorite_colors, + # get_email, + count_favorite_colors, # people_who_like_color, # count_people_who_like_color, # get_color_dict, @@ -22,22 +22,22 @@ from friend_functions import ( # self.assertEqual(count_people(family), 5) # self.assertEqual(count_people(friends), 10) -class TestGetEmail(TestCase): - def test_returns_email_when_person_found(self): - self.assertEqual(get_email(family, "Perry Calderon"), "mus.donec@outlook.org") - self.assertEqual(get_email(friends, "Joy Tate"), "risus.a.ultricies@hotmail.org") - - def test_returns_none_when_person_missing(self): - self.assertEqual(get_email(family, "Ken Kesey"), None) - -# class TestCountFavoriteColors(TestCase): -# def test_returns_len_favorite_colors_when_person_found(self): -# self.assertEqual(count_favorite_colors(family, "Tad Winters"), 2) -# self.assertEqual(count_favorite_colors(friends,"Connor Rodriguez"), 4) -# self.assertEqual(count_favorite_colors(friends, "Yuli Reynolds"), 0) +# class TestGetEmail(TestCase): +# def test_returns_email_when_person_found(self): +# self.assertEqual(get_email(family, "Perry Calderon"), "mus.donec@outlook.org") +# self.assertEqual(get_email(friends, "Joy Tate"), "risus.a.ultricies@hotmail.org") # def test_returns_none_when_person_missing(self): -# self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None) +# self.assertEqual(get_email(family, "Ken Kesey"), None) + +class TestCountFavoriteColors(TestCase): + def test_returns_len_favorite_colors_when_person_found(self): + self.assertEqual(count_favorite_colors(family, "Tad Winters"), 2) + self.assertEqual(count_favorite_colors(friends,"Connor Rodriguez"), 4) + self.assertEqual(count_favorite_colors(friends, "Yuli Reynolds"), 0) + + def test_returns_none_when_person_missing(self): + self.assertEqual(count_favorite_colors(family, "Ken Kesey"), None) # class TestPeopleWhoLikeColor(TestCase): # def test_returns_correct_length(self):