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

Keaton Adams
PLUS
Keaton Adams
Courses Plus Student 449 Points

Hi team, should I be adding a "try" ?

See above

suggestinator.py
def suggest(product_idea):
    if number_of_characters < 3:
        raise ValueError("More than 3 characters needed")
    return product_idea + "More than 3 characters needed"

3 Answers

Haisam Elkewidy
Haisam Elkewidy
26,987 Points

You need to use the len() function. So it would be something like this:

if len(product_idea) < 3: raise ValueError("whatever you want here")

Keaton Adams
Keaton Adams
Courses Plus Student 449 Points

Hi Haisam, Thanks for the help. I tried (below) and it did not work. I often feel like I am missing most obvious things.

def suggest(product_idea): if len(product_idea) < 3: raise ValueError("Need more characters") return product_idea + "Need more characters"

Haisam Elkewidy
Haisam Elkewidy
26,987 Points

Your return statement should be:

return product_idea + "inator"

Because in the console it's expecting a concatenation of the idea name with the inator suffix at the end.

For example: "bacon" + "inator" = "baconinator".

Try this:

def suggest(product_idea): if len(product_idea) < 3: raise ValueError("Need more characters")

return product_idea + "inator"
Keaton Adams
Keaton Adams
Courses Plus Student 449 Points

Perfect thank you! I must have been missing that inator was a suffix term.

Haisam Elkewidy
Haisam Elkewidy
26,987 Points

If any of my answers helped you solve your problem, please consider clicking on the upper arrows and giving me points for Best Answer.