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
kjksj mnzdmndzf
Python Web Development Techdegree Student 142 PointsSyntax error on a challenge question
Make a function how_many that, given a list of a number
and a thing name, returns a grmmatically correct sentence
describing the number of things.
>>>> how_many([5, "trinket"])
There are 5 trinket
>>>> how_many([1, "king"])
There is 1 king
def how_many(the_list):
if the_list[0] == 1:
return ("There is {} {}".format(str(the_list[0]), the_list[1]))
else:
return ("There are {} {}".format(str(the_list[0]), the_list[1]))
print how_many([5, "trinket"])
print how_many([1, "king"])
1 Answer
Jon Mirow
9,864 PointsHi there,
Can't see any problems with the function code, unless you've got an indentation issue... but then that would raise an IndentationError not a SyntaxError. Could you paste in the error message?
One possible solution: are you using python 2 or 3? because 3 would raise a SyntaxError on those print statements?
kjksj mnzdmndzf
Python Web Development Techdegree Student 142 PointsGotcha I was using python 3. So silly mistake. Thanks Jon
Jon Mirow
9,864 PointsNo worries, we all do it :) I keep on confusing python 3 with dict.iteritems() lol!
Steven Parker
243,656 PointsSteven Parker
243,656 PointsTo make posted code readable, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.