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

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!