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

Am I even close?

I feel like this accurately shows my current understanding of where I am. Im not sure where I went wrong.

suggestinator.py
try:
    def suggest(product_idea):
        return product_idea + "inator"
        except ValueError:
            if product_idea < 3:
                raise ValueError

1 Answer

The challenge is expecting a ValueError to be raised, and not caught by a try-except block. If you did need a try-except block, the try: and except ValueError: should be at the same indentation level, such as

try:
    pass
except ValueError:
    pass

Once you return from a function, the rest of the function gets ignored. Try moving the if block so that it is before the return statement.

Currently, the if statement compares the variable product_idea, which is a string, to the number 3. To instead use the length of the string, try using the len() function.

Thank you that gives me much more clarity, you have my gratitude!