generated from mwc/lab_weather
I completed the functions on the friends document
to complete the tests. I am sorry in advance, I read the prompt for the submission wrong, I thought it said to submit once you had the functions finalized, it was only after I worked through them all that I understood that I was supposed to submit after each function. That being said, one thing that helps me a lot when working through this code is the feedback from the error messages and the examples that you provide in the directions. I am finding that I am the kind of person that has a really difficult time conceptualizing a task unless I have an example in front of me. Once I can see what something is meant to look like, then I can play with the tools provided and make soething meaningful. While I am going through this process I reflect on my students and what they feel as they learn a new process. It makes me think that there is a much needed balance between productive struggle and showing them exactly what their product could look like, then letting them find the solutions. So, while I worked through this section of the lab I found myself looking online at other examples of functions that use dictionaries and lists. Once I had more examples of what the products should look like, I was able to work my way through each function. Again, I found myself making a handful of changes, then running the test to get feedback on my work. Within any classroom, I think that this kind of instant feedback is really meaningful. It allows you to know exactly what to adjust then allows you the space to get creative with the solution. It is like a combination of math and ELA. Just the right amount of, there is one right answer, and you can try a bunch of things, then get feedback.
This commit is contained in:
parent
fbac66abe9
commit
8fb45591c9
|
@ -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,19 +27,27 @@ def get_email(people, name):
|
|||
>>> get_email(friends, "Tad Winters")
|
||||
None
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
for person in people:
|
||||
if person.get("name") == name:
|
||||
return person.get("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.
|
||||
"""Returns the number of colors liked by the named person. If there is no such person, returns None."""
|
||||
for person in people:
|
||||
if person.get("name") == name:
|
||||
return len(person.get("favorite_colors", []))
|
||||
return None
|
||||
|
||||
>>> count_favorite_colors(family, "Tad Winters")
|
||||
2
|
||||
>>> count_favorite_colors(family, "Raphael Chambers")
|
||||
1
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def people_who_like_color(people, color):
|
||||
"""Returns a list containing only those people who like the given color."""
|
||||
result = []
|
||||
for person in people:
|
||||
if color in person.get("favorite_colors", []):
|
||||
result.append(person)
|
||||
return result
|
||||
|
||||
"""Returns a list containing only those people who like the given color.
|
||||
>>> people_who_like_color(family, "yellow")
|
||||
[
|
||||
|
@ -57,19 +65,25 @@ def people_who_like_color(people, color):
|
|||
>>> people_who_like_color(family, "indigo")
|
||||
[]
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
"""Returns a list containing only those people who like the given color."""
|
||||
"Returns a list containing only those people who like the given color."""
|
||||
|
||||
def count_people_who_like_color(people, color):
|
||||
"""Returns the number of people who like a given color.
|
||||
|
||||
>>> count_people_who_like_color(family, "red")
|
||||
2
|
||||
>>> count_people_who_like_color(family, "orange")
|
||||
1
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
"""Returns the number of people who like a given color."""
|
||||
count = 0
|
||||
for person in people:
|
||||
if color in person.get("favorite_colors", []):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
def get_color_dict(people):
|
||||
"""Returns a dict showing how many people like each color."""
|
||||
color_dict = {}
|
||||
for person in people:
|
||||
for color in person.get("favorite_colors", []):
|
||||
color_dict[color] = color_dict.get(color, 0) + 1
|
||||
return color_dict
|
||||
|
||||
"""Returns a dict showing how many people like each color.
|
||||
Any color liked by any of the people will be included, and only colors
|
||||
liked by someone will be included. The order of items in the dict doesn't matter.
|
||||
|
@ -86,7 +100,8 @@ def get_color_dict(people):
|
|||
"orange": 1,
|
||||
}
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
"""Returns a dict showing how many people like each color."""
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue