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

Can someone explain why this is wrong for me please.

Can someone explain why this is wrong to me please. I am using the input method.

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

2 Answers

Hi Darrin,

I remember this challenge, and it still continues to stump me! The instructions and the overall topic was confusing too, in my experience.

In your code, the error is caused by your 2 input() calls.

My suggestion: please write your second line so that it uses dict. Here's an example I can give you:

# Goal: to print 'The quick brown fox jumps over the lazy dog'

def print_example(dict):
    return "The quick brown {jumping_animal} jumps over the lazy {lazy_animal}".format(**dict)

dict_animals = {'jumping_animal':'fox', 'lazy_animal':'dog'}
print_example(dict_animals)

as a side-note, if you can pass this challenge today, and weeks from now not be able to memorize how, always referring to notes like I still do, life will go on :)

Ohhh I thought the ** was supposed to be used with *kwargs only. I thought that was a command. So that * and a the parameter of the function I can use that to unpack it???

**kwargs** has been confusing for most of us students. The fact is that kwargs is the name of an ordinary dictionary inside the function. By ordinary, I mean it could have been named anything, like **dictionary, **dict or **keywordarguments. The Python convention is to name it kwargs. Hope that helps :)

So anything in the parameter of the function can be unpacked with ** but kwargs is just the common name pythoniers like to name it. Is that what you mean?

So anything in the parameter of the function can be unpacked with ** but kwargs is just the common name pythoniers like to name it. Is that what you mean?

couldn't have said it better myself.

Wesley Trayer
Wesley Trayer
13,812 Points

Your ".format" should unpack the dictionary passed into the "favorite_food" function as an argument, and use the information in the dictionary as the arguments for ".format". The challenge is not looking for the "input()" function, so it can not fill those in.

Hope this helps!

I think I get what you're saying now.