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

What code can I use to detect if a string comes back less than 3 characters long?

I know I can't use < 3 or < (" ") with three spaces. Would I need to create a new function for this?

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

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there. Kyler Aagard! I received your request for assistance. I feel like you might have forgotten the len() which will return the length of a string (or list or dictionary).

For example:

school = "Treehouse"
school_length = len(school)

At the end of this, school_length will contain the value 9.

Hope this helps! :sparkles: