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 Python Basics Functions and Looping Raise an Exception

I am stuck on writing the code for ChalTask 1 of 1 on the suggestionator.py. Need help on if product_idea < 3 characters

I don't know how to establish a length for the characters entered.

import math

def suggest(product_idea):
    if product_idea < (len)too:
        raise ValueError
    return product_idea + "inator"

    product_idea = input("What is your idea?   ")
    idea_answer = suggest(product_idea)

4 Answers

Steven Parker
Steven Parker
229,921 Points

Use the "len" function to get the length of an item:

    if len(product_idea) < 3:

Also, you only need to change the function definition, you won't need to get any input or call the function.

Thank you for the quick reply Steven! This is helpful. I am however receiving 2 syntaxerror: invalid syntax. Any thoughts on this?

Steven Parker
Steven Parker
229,921 Points

Did you get rid of the extra stuff after the function? If that's not it I'd probably need to see the code as it is now (properly formatted!).

I did. My code thus far is...

def suggest(product_idea): if (len)product_idea < 3: raise ValueError("More than 2 characters are required") return product_idea + "inator"

Appreciate your help, Steven!

Steven Parker
Steven Parker
229,921 Points

It's really hard to make sense of that without formatting.

Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:
Or watch this video on code formatting.

But take another look at the code line I first suggested. When calling a function, the parentheses come after the function name and enclose the argument(s). It looks like you have them around the function name here.

My mistake, I just realized after your last answer I had the parentheses around the function. Silly mistake that I kept overlooking.

Thanks so much for talking me through this!