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 trial

Python Python Collections (2016, retired 2019) Dictionaries String Formatting with Dictionaries

what is wrong with this code?

def favorite_food(**dict): return "Hi, I'm {name} and I love to eat {food}!".format(name= dict["name"], food = dict["food"])

string_factory.py
def favorite_food(**dict):
    return "Hi, I'm {name} and I love to eat {food}!".format(name= dict["name"], food = dict["food"])

3 Answers

Holden Glass
Holden Glass
6,077 Points

I went and looked at the problem and you are being passed a dictionary, not multiple arguments that you need to pack into a dictionary, I think. Try leaving the parameter as dict with no ** and try using it as a dict in the format.

Holden Glass
Holden Glass
6,077 Points

The name that you used for your parameter is a python keyword. Something like def favorite_food(**a_dict): should work.

Thank you Holden, I tried the following:

def favorite_food(**a_dict): return "Hi, I'm {name} and I love to eat {food}!".format(name= a_dict["name"], food = a_dict["food"])

But that did not work either!

Thanks Holden! That did it!