Python Python Basics Functions and Looping Raise an Exception

Erwan Mba Mba
Erwan Mba Mba
2,711 Points

Please any suggestion on how to solve this challenge???

I don't know if there is something that I'm missing.

suggestinator.py
def suggest(product_idea):
    if product_idea < 3 words:
    raise ValueError ("product_idea is less than 3 characters long")
    return product_idea + "inator"

2 Answers

Christian Beckett
Christian Beckett
11,118 Points

Hi The whole point of the challenge is to raise a value error so in order to do so you must take the len() of the code making the code for it if len(product_idea) < 3: raise ValueError ("product_idea is less than 3 characters long") or whatever you would like ot make it.

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! The challenge is looking for you to raise an error if the product_idea being passed in is less than 3 characters not words. In your code, words is not defined. It doesn't exist anywhere and Python doesn't know what this variable is. In order to know how many characters are in a string, you need to use len() and then see if it is less than 3. If so, you raise the error, but the error should be inside of the if block, right now it is outside of the if block so the error runs every time. The amount of spaces or tabs is important in Python, so you need to tab your raise statement over so it is like this:

if len(product_idea) < 3:
    raise ValueError ("product_idea is less than 3 characters long")