Python Python Basics Functions and Looping Raise an Exception

Luiz Peres
Luiz Peres
717 Points

def suggest(product_idea): if product idea len( < 3 ): raise ValueError "product idea is less than 3 charact

Evening everyone!! Got stuck on this code, anyone able to help?

Many thanks!!

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

3 Answers

Robert Peters
Robert Peters
3,580 Points

Hi. Well I think that you missed the _ in product_idea, making it act as 2 different variables. Also, that line should be:

if len(product_idea) < 3:

Then below that, should be:

raise ValueError("product idea is less than 3 characters long")

Hope this helps!

Luiz Peres
Luiz Peres
717 Points

Hey Robert!! Many thanks for your help!! You nailed it!!

Regards,

Luiz

Just be sure to check the labels/names to make sure they match

def suggest(product_idea):
    if product idea len( < 3 ): # product idea - should match wherever the parameter is used - product_idea
        raise ValueError "product idea is less than 3 characters long"
    return product_idea + "inator"

Also, since watching the video about raising exceptions and reading tracebacks I have been trying to read and watch everything about accurately understanding tracebacks. Not sure if this is allowed. If its not I apologize in advance. https://www.youtube.com/watch?v=3p3p6kp39to&t=293s <--- this really helped me

Cheers.