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 Raising Exceptions

Dennis Callahan
Dennis Callahan
375 Points

Need help with raising exception coding challenge.

Not sure where I'm going wrong...here's the ask "raise a ValueError if the product_idea is less than 3 characters long? any ideas why my code won't work? Thanks for any help!

product_idea is a string. suggest(product_idea): if product_idea len <3: raise ValueError return product_idea + "inator"

Dennis Callahan
Dennis Callahan
375 Points

Answered my own question from using community...had the 2nd line backward

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

2 Answers

Bernhard Chis
Bernhard Chis
3,296 Points

Hey buddy, I had the same problem as you.

I was not used to the indentation of Python by the time of the challenge. Nevertheless, after spending a minute just looking at the code it became obvious that I failed to indent properly :) Perhaps you forgot 'def' or some minor change, you'll probably find it if you haven't already.

I passed with the following code, which is very similar to yours:

def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError
    return product_idea + "inator"
Christopher Gunawan
Christopher Gunawan
10,754 Points

try wrapping your code with (place above the first line of your code). It will help make your code more readable to people viewing the discussion. For example:

code here

Make sure you end the code with ``` in a new line.