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

Luiz Peres
Luiz Peres
1,242 Points

def suggest(product_idea): if product idea len( < 3 ): raise ValueError "product idea is less than 3 charact

Evening everyone!! Got stuck on this code, anyone able to help?

Many thanks!!

suggestinator.py
def suggest(product_idea):
    if product idea len( < 3 ):
        raise ValueError "product idea is less than 3 characters long"
    return product_idea + "inator"

3 Answers

Hi. Well I think that you missed the _ in product_idea, making it act as 2 different variables. Also, that line should be:

if len(product_idea) < 3:

Then below that, should be:

raise ValueError("product idea is less than 3 characters long")

Hope this helps!

Luiz Peres
Luiz Peres
1,242 Points

Hey Robert!! Many thanks for your help!! You nailed it!!

Regards,

Luiz

Just be sure to check the labels/names to make sure they match

def suggest(product_idea):
    if product idea len( < 3 ): # product idea - should match wherever the parameter is used - product_idea
        raise ValueError "product idea is less than 3 characters long"
    return product_idea + "inator"

Also, since watching the video about raising exceptions and reading tracebacks I have been trying to read and watch everything about accurately understanding tracebacks. Not sure if this is allowed. If its not I apologize in advance. https://www.youtube.com/watch?v=3p3p6kp39to&t=293s <--- this really helped me

Cheers.