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

Syntax 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"])

Steven Parker
Steven Parker
243,656 Points

To make posted code readable, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:

1 Answer

Hi 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?

Gotcha I was using python 3. So silly mistake. Thanks Jon

No worries, we all do it :) I keep on confusing python 3 with dict.iteritems() lol!