Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGarrett Hughes
Python Development Techdegree Student 32,971 PointsI have no idea what I'm doing on this exercise. I've watched the video preceding it at least 6 times.
Something's just not clicking with this exercise for me. Haven't had any trouble with python up to this point. I tried to base my answer off what Kenneth did in the video. What am I doing incorrectly here?
# Example:
# values = [{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]
# string_factory(values)
# ["Hi, I'm Michelangelo and I love to eat PIZZA!", "Hi, I'm Garfield and I love to eat lasagna!"]
template = "Hi, I'm {name} and I love to eat {food}!"
def string_factory(name = None, food = None):
list = []
if name and food:
new = template.format(name,food)
list.append(new)
return new
1 Answer
Alexander Davison
65,469 PointsI think you misunderstood the challenge.
The function takes in only one argument. It is a list of dictionaries.
Here's a sample parameter:
[{"name": "Michelangelo", "food": "PIZZA"}, {"name": "Garfield", "food": "lasagna"}]
If you call the complete string_factory
function with that argument, you should get this in return:
["Hi, I'm Michelangelo and I love to eat PIZZA!", "Hi, I'm Garfield and I love to eat lasagna!"]
Does this help?
Zachary Crane
1,736 PointsZachary Crane
1,736 PointsThat helps a ton! I had no idea what they were asking for either.