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 trialDarrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsCan 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.
def favorite_food(dict):
return "Hi, I'm {name} and I love to eat {food}!".format(name = input(), food = input())
2 Answers
Mark Chesney
11,747 PointsHi 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)
Wesley Trayer
13,812 PointsYour ".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!
Darrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsI think I get what you're saying now.
Mark Chesney
11,747 PointsMark Chesney
11,747 Pointsas 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 :)
Darrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsDarrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsOhhh 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???
Mark Chesney
11,747 PointsMark Chesney
11,747 Points**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 itkwargs
. Hope that helps :)Darrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsDarrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 PointsSo 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?
Mark Chesney
11,747 PointsMark Chesney
11,747 Pointscouldn't have said it better myself.