Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Raise an Exception

Kennedy Malonga
Kennedy Malonga
13,411 Points

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

where should i test the length of the string instead of the string itself will int() be needed anywhere

suggestinator.py
def suggest(product_idea):
    if product_idea < 3:
        raise ValueError("characters too short")
    return product_idea + "inator"

3 Answers

Steven Parker
Steven Parker
217,469 Points

You won't need int(), but you might need to use the len() function.   :wink:

Kennedy Malonga
Kennedy Malonga
13,411 Points

finally got it right by mistake

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

Steven Parker
Steven Parker
217,469 Points

No "mistake" there – you got it!   :+1:

Lindsey Mote
seal-mask
.a{fill-rule:evenodd;}techdegree
Lindsey Mote
Data Analysis Techdegree Student 1,147 Points

I'm stuck on this one as well! I used the same code as suggested by Kennedy above and got the following error: AssertionError: None != 'baconinator' : I passed in 'bacon' and expected 'baconinator', but got 'None'

Steven Parker
Steven Parker
217,469 Points

Try creating a fresh question where your exact code will be shown.