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

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")
boi
boi
14,242 Points

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

how did you figure it out?

boi
boi
14,242 Points

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

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")

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

1 Answer

boi
boi
14,242 Points
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.