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

Taylor Han
Taylor Han
3,701 Points

Issues raising ValueError

Hello,

I'm stuck on how to raise the ValueError. I think the syntax is ok, but challenge says its missing something.

suggestinator.py
if len("product_idea") <= 3:
    raise ValueError ("At least three characters please")

def suggest(product_idea):
    return product_idea + "inator"

2 Answers

Hi Taylor,

It appears that your ValueError statement is outside of the function. Try placing your if/ValueError inside the function, above the return.

Also, you wrote: if len("product_idea") <= 3:. This will make product_idea a string. Try dropping the quotes so it will be read accurately by the computer.

With those 2 small changes, your code should look something like this:

suggestinator.py
def suggest(product_idea):
    if len(product_idea) <= 3:
        raise ValueError ("At least three characters please")
    return product_idea + "inator"

Cheers!

Taylor Han
Taylor Han
3,701 Points

Ah thank you for showing me the code too! It was driving me nuts haha. I got it now, thanks!

You've got the right idea with almost perfect code but you have to put your if statement inside the function. IF the product idea isn't long enough then raise an error ELSE it should return " product_idea + "inator" "