generated from mwc/lab_weather
I wrote all the fucntions in the friend_functions. The first two were done from the weekly video, the rest were done by me using the lab notes.
I am a little behind on my labs so I have't programed in a while. Due to this, I struggled to get started and remembering how to use iterations. I struggled mostly with the last 2 functions, but once i remembered how to create a list and how to keep count, the final function became easier for me. I combine the smaller funcitons to help me with the more complex function. Since I undrstood the smaller sutff, I was able to play around to use that learning for the bigger stuff. I looked through the earlier functions codes and ran therough how they work to help me when i got stuck.
This commit is contained in:
@@ -17,7 +17,8 @@ def count_people(people):
|
|||||||
>>> count_people(friends)
|
>>> count_people(friends)
|
||||||
10
|
10
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
return len(people)
|
||||||
|
|
||||||
|
|
||||||
def get_email(people, name):
|
def get_email(people, name):
|
||||||
"""Returns the named person's email address. If there is no such person, returns None.
|
"""Returns the named person's email address. If there is no such person, returns None.
|
||||||
@@ -27,7 +28,12 @@ def get_email(people, name):
|
|||||||
>>> get_email(friends, "Tad Winters")
|
>>> get_email(friends, "Tad Winters")
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
|
||||||
|
for person in people:
|
||||||
|
if name == person['name']:
|
||||||
|
return person['email']
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
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.
|
"""Returns the number of colors liked by the named person. If there is no such person, returns None.
|
||||||
@@ -37,7 +43,10 @@ def count_favorite_colors(people, name):
|
|||||||
>>> count_favorite_colors(family, "Raphael Chambers")
|
>>> count_favorite_colors(family, "Raphael Chambers")
|
||||||
1
|
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):
|
def people_who_like_color(people, color):
|
||||||
"""Returns a list containing only those people who like the given color.
|
"""Returns a list containing only those people who like the given color.
|
||||||
@@ -57,7 +66,15 @@ def people_who_like_color(people, color):
|
|||||||
>>> people_who_like_color(family, "indigo")
|
>>> people_who_like_color(family, "indigo")
|
||||||
[]
|
[]
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
|
||||||
|
like = []
|
||||||
|
|
||||||
|
for person in people:
|
||||||
|
if color in person["favorite_color"]:
|
||||||
|
like.append(person)
|
||||||
|
|
||||||
|
return like
|
||||||
|
|
||||||
|
|
||||||
def count_people_who_like_color(people, color):
|
def count_people_who_like_color(people, color):
|
||||||
"""Returns the number of people who like a given color.
|
"""Returns the number of people who like a given color.
|
||||||
@@ -67,7 +84,14 @@ def count_people_who_like_color(people, color):
|
|||||||
>>> count_people_who_like_color(family, "orange")
|
>>> count_people_who_like_color(family, "orange")
|
||||||
1
|
1
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
count = 0
|
||||||
|
|
||||||
|
for person in people:
|
||||||
|
if color in person['favorite_color']:
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
def get_color_dict(people):
|
def get_color_dict(people):
|
||||||
"""Returns a dict showing how many people like each color.
|
"""Returns a dict showing how many people like each color.
|
||||||
@@ -86,7 +110,17 @@ def get_color_dict(people):
|
|||||||
"orange": 1,
|
"orange": 1,
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
count = 0
|
||||||
|
|
||||||
|
for person in people:
|
||||||
|
for color in person["favorite_color"]:
|
||||||
|
if color in count:
|
||||||
|
count[color] +=1
|
||||||
|
else:
|
||||||
|
count[color]== 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user