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 trialParth Pandya
678 PointsError: string_factory() missing 1 required positional argument: 'template', but works in IDE
Heres my code, I keep getting the error mentioned in the title:
dicts = [ {'name': 'Michelangelo', 'food': 'PIZZA'}, {'name': 'Garfield', 'food': 'lasanga'}, {'name': 'Walter', 'food': 'pancakes'}, {'name': 'Galactus', 'food': 'worlds'} ]
template = "Hi, I'm {name} and I love to eat {food}!"
def string_factory(dicts, template): strings = [] for items in dicts: strings.append(template.format(**items)) return strings
string_factory(dicts, template)
frankgenova
Python Web Development Techdegree Student 15,616 Pointstemplate is a global variable established outside of the loop, I don't think you have to pass it to the routine, however I'm not sure that is what the issue is
1 Answer
Steven Parker
231,269 PointsYou should only take one argument.
The instructions say to write a function "that accepts a list of dictionaries as an argument". But your function requires a list of dictionaries and a template. You'll make use of the global template in your function, you won't get one as an argument.
And just define your function. Don't also call it (or define your own list of dicts).
frankgenova
Python Web Development Techdegree Student 15,616 Pointsfrankgenova
Python Web Development Techdegree Student 15,616 PointsParth Try posting in markdown, the instructions are in the hyperlink below the posting window. It will look like this.