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

I believe my code is correct for string_factory.py but it will not pass, any help would be appreciated.

I have tried changing the name and the food and have tried refactoring the code some, it will return the correct statement in my work spaces but it does not seem to work here. I have messed around with the white space in the dict too to no avail.

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

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi John,

Your function has a parameter named dict. This is the name you should be using in the body of the function to access that value, not my_dict.

You should also delete your definition of the my_dict variable, it is not needed.

Cheers

Alex

I have been stuck on this problem for a few hours now. Your answer helped me so much! Thank you!

This one threw me for a loop, too. Especially since my code below worked in an IDE, and was pretty much taken exactly from the previous lesson...

def favorite_food(name=None, food=None):
    if name and food:
        print("Hi, I'm {} and I love to eat {}!".format(name, food))

favorite_food(**{"name": "Joshua", "food": "pizza"})

It was both frustrating and a relief to find that the answer was as simple as **dict in the .format parentheses.