I did the fuction for finding people who like certain color.

This commit is contained in:
Seoyeon Lee 2024-12-06 23:34:18 -05:00
parent b23ec92c37
commit 619c975e65
1 changed files with 14 additions and 4 deletions

View File

@ -17,7 +17,7 @@ def count_people(people):
>>> count_people(friends)
10
"""
raise NotImplementedError()
return len(people)
def get_email(people, name):
"""Returns the named person's email address. If there is no such person, returns None.
@ -27,7 +27,9 @@ def get_email(people, name):
>>> get_email(friends, "Tad Winters")
None
"""
raise NotImplementedError()
for person in people:
if person["name"] == name:
return person["email"]
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 +39,10 @@ def count_favorite_colors(people, name):
>>> count_favorite_colors(family, "Raphael Chambers")
1
"""
raise NotImplementedError()
for person in people:
if person["name"] == name:
return len(person["favorite_colors"])
return None
def people_who_like_color(people, color):
"""Returns a list containing only those people who like the given color.
@ -57,7 +62,12 @@ def people_who_like_color(people, color):
>>> people_who_like_color(family, "indigo")
[]
"""
raise NotImplementedError()
peoplelist=[]
for person in people:
if color in person["favorite_color"]:
peoplelist.append(person["name"])
return peoplelist
def count_people_who_like_color(people, color):
"""Returns the number of people who like a given color.