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

Can you please raise a ValueError if the product_idea is less than 3 characters long? product_idea is a string. Thanks

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

1 Answer

Josh Keenan
Josh Keenan
19,652 Points

To complete this challenge you need to use len() to get the length of the string.

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

Here's my solution, it checks if the length of the string product_idea is less than 3, if it is then it will raise the value error, if it doesn't trigger this clause, then it will just go to the return statement. Hope this makes sense.

omg i didnt for form the the first place then i thy different methos and then i capy and paste and it work HOW!

thans tho.......

Josh Keenan
Josh Keenan
19,652 Points

Happy to help, your code has a few issues, firstly you fail to check the length of the string at any point which is what we need to be examining, you also used <= instead of < which would cause the code to fail as these are different.

One will accept the string that is 3 characters and the other won't.