From 2899a3250a666d0a828948982bff9925fac56167 Mon Sep 17 00:00:00 2001 From: ilmabura Date: Mon, 20 Oct 2025 16:01:43 -0400 Subject: [PATCH] created the first two functions of friend_functions I didn't properly read the instructions and I kept getting confused by what the data looked like so I created a trials folder and I used it to dissect the data. Once it was clear that I was looking at a list of dictionaries, it became very easy to create my first two functions. It's necessary to know what the dataset looks like structurally. --- friend_functions.py | 15 ++++--- trials.py | 95 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 trials.py diff --git a/friend_functions.py b/friend_functions.py index 6f5ecf7..c4bb836 100644 --- a/friend_functions.py +++ b/friend_functions.py @@ -8,7 +8,7 @@ # Your job is to complete these functions. Remove the NotImplementedError from # each and instead write code which returns the expected values. - +from people import * def count_people(people): """Counts the number of people. @@ -17,7 +17,9 @@ def count_people(people): >>> count_people(friends) 10 """ - raise NotImplementedError() + count=len(people) + return count + def get_email(people, name): """Returns the named person's email address. If there is no such person, returns None. @@ -27,7 +29,11 @@ def get_email(people, name): >>> get_email(friends, "Tad Winters") None """ - raise NotImplementedError() + for n in people: + if n['name']== name: + return n['email'] + else: + 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. @@ -90,5 +96,4 @@ def get_color_dict(people): - - +print(get_email(friends, "Tad Winters")) diff --git a/trials.py b/trials.py new file mode 100644 index 0000000..4d8ecbd --- /dev/null +++ b/trials.py @@ -0,0 +1,95 @@ +family = [ + { + "name": "Tad Winters", + "email": "ligula.aenean@hotmail.edu", + "favorite_colors": ["aqua", "red"], + }, + { + "name": "Raphael Chambers", + "email": "ac.eleifend.vitae@protonmail.com", + "favorite_colors": ["blue"], + }, + { + "name": "Perry Calderon", + "email": "mus.donec@outlook.org", + "favorite_colors": ["black", "white", "grey"], + }, + { + "name": "Walker Hurley", + "email": "auctor.odio@icloud.ca", + "favorite_colors": ["red", "yellow", "blue", "orange"], + }, + { + "name": "Clementine Joseph", + "email": "hendrerit@aol.co.uk", + "favorite_colors": ["yellow", "aqua", "black"], + } +] + +friends = [ + { + "name": "Connor Rodriguez", + "email": "maecenas@yahoo.edu", + "favorite_colors": ["aqua", "teal", "sea foam", "turquoise"], + }, + { + "name": "Rosalyn Hubbard", + "email": "elit.pharetra@google.edu", + "favorite_colors": ["red", "yellow", "black"], + }, + { + "name": "Thomas Puckett", + "email": "sit.amet@aol.net", + "favorite_colors": ["blue"], + }, + { + "name": "Yuli Reynolds", + "email": "augue.malesuada@google.edu", + "favorite_colors": [], + }, + { + "name": "Joy Tate", + "email": "risus.a.ultricies@hotmail.org", + "favorite_colors": ["white", "grey", "sand"], + }, + { + "name": "Prescott Price", + "email": "cursus.nunc@yahoo.edu", + "favorite_colors": ["red", "blue", "green"], + }, + { + "name": "Josephine Keller", + "email": "nulla@protonmail.edu", + "favorite_colors": ["black"], + }, + { + "name": "Isadora Carney", + "email": "sagittis.lobortis@protonmail.co.uk", + "favorite_colors": ["aqua", "lime"], + }, + { + "name": "Jelani West", + "email": "vehicula.pellentesque.tincidunt@yahoo.org", + "favorite_colors": ["grey", "beige", "tan"], + }, + { + "name": "Gay Pittman", + "email": "etiam.bibendum@yahoo.org", + "favorite_colors": ["yellow"], + } +] + +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 + """ + +for n in friends: + if n['name']=="Tad Winters": + print(n['email']) + else: + print(None)