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

Himanshu Patil
Himanshu Patil
448 Points

Raise error

what is wrong with my code

suggestinator.py
def suggest(product_idea):
    return product_idea + "inator"
        if len(product_idea) < 3:
        raise ValueError("Need more that 3 chars")
Daron Anderson
Daron Anderson
2,567 Points

Your brain is really sharp, I didnt know to use len, saw your code and was like oh theres my answer and instantly I knew your return should have been at the bottom of the raise aligned with the if. Two brains are always better than one. Thanks man. Great Job! dont get discouraged your built for this.

4 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Your code is correct, but just a little out of order. The "if" statement needs to test the length of the product_idea and raise an error before we return the product_idea + "inator"

see below

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

Good luck with your Python journey!

Himanshu Patil
Himanshu Patil
448 Points

Thank you for your quick response.

Hi there, Jeff I am stuck on code challenge on "Python basics ", raising an exception I did everything like you said but still got an error. ! Imgur

Daron Anderson
Daron Anderson
2,567 Points

@Nurtilek Taalaibekov, Your if statement needs to be aligned with your return statement. its an indentation error.

Daron Anderson
Daron Anderson
2,567 Points

This little section was the highlight of my day.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

@Nurtilek Taalaibekov -- what is the error message you are getting?