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

Why am I getting this syntax error?

I am just starting learning python and keep getting this syntax error for a quiz even though I basically copied and pasted it from the lesson (changing the names and numbers as needed). Any help would be greatly appreciated. The error comes at line 8 or "number_of_characters = len(product_idea)".

It won't let me add a screenshot? But the code is as follows: def suggest(product_idea, number_of_characters): if number_of_characters < 3: raise ValueError("Please add to the product idea.") return product_idea + "inator"

try: product_idea = int(input("What is the product idea? ") number_of_characters = len(product_idea) product_name = suggest(product_idea, number_of_characters) except ValueError as err: print("Oh no! That's not a valid value. Try again...") print("({})".format(err)) else:
print("The product name could be {}.".format(product_name))

Erlend Dybvik Indrelid
Erlend Dybvik Indrelid
5,843 Points

Hi! You can use the Markdown Cheatsheet to format the code so it shows up in a much more readable way. The way you do it is by surrounding your code in three ` both in the start, as well as in the end. After the starting three `, you can write "python" so the colors show up correctly. I will be happy to answer your question when you have done this, but the code is too hard to read in its current state. -Erlend

1 Answer

Steven Parker
Steven Parker
231,261 Points

Definitely always use Markdown formatting when posting code.

But you've clearly done several things not asked for by the instructions that are confusing the validation:

  • you only need to add code to the function itself, don't add any after the function
  • you don't need to "input" or "print" anything, and you won't need "try" or "except"
  • you're not allowed to change the calling signature (as by adding another parameter)
  • you must determine the length from the string itself (by using a function on it)