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

dominicchoi
dominicchoi
976 Points

I can't get to correct answer for the challenge of string formatting with dictionary.

I'm not sure what is the correct answer for the string formatting with dictionary challenge. The following is how my script looks:

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

favorite_food(**{"food":"choco" , "name":"John"})

string_factory.py
def favorite_food(food=None,name=None):
    return "Hi, I'm {name} and I love to eat {food}!".format(name="Dom",food="choco")


favorite_food({"food":"choco" , "name":"Dom"})

1 Answer

Michael Dioszeghy
Michael Dioszeghy
2,412 Points

In the code block, it looks like you are trying to re-assign the name and food when it is already being passed in by the function.

The code above it, that is not in the code block, looks like it is done correctly, but you need another ')' after the food after format: def favorite_food(food=None,name=None): return "Hi, I'm {name} and I love to eat {food}!".format(name, food)}