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'm needing help raising a ValueError

I've made a function that creates brand new product names using "artificial intelligence".

I have a problem though, pe

suggestinator.py
def suggest(product_idea):
    if product_idea <= 3:
        raise ValueError("produc_value" <= 3)
    return product_idea + "inator"

4 Answers

Hi Christopher

You are very close! You are just missing the len() here and all should be good:

def suggest(product_idea):
    if len(product_idea) <= 3:
        raise ValueError("product_value")
    return product_idea + "inator"

As the text in the code challenge says -> people keep on adding product ideas that are too short. So you need to check the length of product_idea and you can do it like this:

if len(product_idea) <= 3:

EDIT: You also might want to change the message here in quotes:

raise ValueError("product_value")

Maybe something like "The length of you product idea is too short".

Hope this helps!

Thanks so much!

What does len() mean?

def suggest(product_idea): if product_idea <= 3: raise ValueError ("product_value") return product_idea + "inator"

After fixing the grammatical error, I'm totally clueless about the next step to run the code.

boi
boi
14,242 Points

You have a total of Three errors, a TypeError and a Syntax error and a challenge requirement error in your code.

def suggest(product_idea):
    if product_idea <= 3:   #TypeError and challenge requirement error
        raise ValueError("produc_value" <= 3) #Invalid syntax
    return product_idea + "inator"

The TypeError is because you are comparing a string product_idea and an int <=3 which don't always get along. I want you to find a way to determine the length of the product_idea and compare that to <=3 which should work.

The Challenge requires you to insert a condition for less than three words NOT less than.

and finally raise ValueError("produc_value" <=3) is an invalid syntax or simply this is wrong grammar, this sentence to the program makes no sense. I want you to experiment with the ("produc_value" <=3) part and find what is grammatically wrong or maybe a type error.

If you tried but failed, and need the solution just comment on this post.

No problem, Christopher, happy to help!