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 have a problem though, people keep on adding product ideas that are too short. It makes the suggestions look bad.

Need help please tell me what I am doing wrong I am getting a syntax error on line 6.

suggestinator.py
def suggest(product_idea):
    return product_idea + "inator"

raise  ValueError("product_idea < 3 characters long?")

except ValueError:                      
      print("Thanks in advance!")

1 Answer

@Karen Shumate A couple of problems here. <^_^>

1) Your statements are outside of the function.

2) Strings are strings, not conditional statements . So, my suggestion is: don't use string as conditional statements like this: raise ValueError("product_idea < 3 characters long?") .

3)To use 'except' you need a 'try' as well.

***Also, You don't need to use 'except' in this problem.

INSIDE the function you can use an if conditional statement to find out if the product_idea is less than 3 characters, and if it is then use: raise ValueError

To measure the length of the product_idea use: the function len(). This is an example: len(product_idea)

So,

Inside the function use this ----> if len(product) < 3:

Within the conditional statement use -----> raise ValueError

Then follow the if with an else statement

Within the else ----> return product_idea + "inator"

Catch my drift?

Moderator Edit: Moved response from Comment to Answer