Python Python Basics Functions and Looping Raise an Exception

Question on "Raise an Exception" Objective 1 [Solved]

Am I misusing len() to represent the number of characters in the product_idea ??

suggestinator.py
def suggest(product_idea):
    return product_idea + "inator"
if len() <= 3:
    raise ValueError (product_idea + "must be longer than characters")

Yes, you're. Need help with the solution?

nah i figured it out yesterday but thank you for responding. Btw, I like your avatar and your name lol

Anesu Antonatte Chibanda Past your code, let me have a look.

Anesu Antonatte Chibanda
Anesu Antonatte Chibanda
2,238 Points

boi cant seem to convert my code so here is the copy and past

def suggest(product_idea): return product_idea + "inator" if product_idea <=3: raise ValueError(product_idea +"characters must be longer than that")

def suggest(product_idea): 
    return product_idea + "inator" 
    if product_idea <=3: 
        raise ValueError(product_idea +"characters must be longer than that")

To learn how to paste your code go here

Now let's analyze your code. You have 3 errors and 1 unnecessary line.

def suggest(product_idea): 
    return product_idea + "inator" 👈# Error 1
    if product_idea <=3: 👈# Error 2 and Error 3
        raise ValueError(product_idea +"characters must be longer than that") 👈# Extra code

Error 1

The return statement returns the value from a function and ends the function. So return should always be called at the end of a function.

Error 2

The product_idea argument is expecting a string object NOT an integer object. So basically you're telling the code to compare a string object to an int object 👉 if string <= 3 which is a wrong statement. Instead, you should be telling the code to compare the length of the string object to an integer object. In the case of getting a length of an object, it would give you back an integer. Which is what you should do.

Error 3

You stated <= 3 which means less OR equal to three, but the challenge wants you to make sure it is LESS than three, so even if the length is equal to three that's acceptable.

Extra code

You only need to raise ValueError, but although it works as it is.

If you need more help, let me know.

Anesu Antonatte Chibanda
Anesu Antonatte Chibanda
2,238 Points

boi Thank you so much i managed to execute it!!